Jump to content
Tuts 4 You

help in delphi 8


mdj

Recommended Posts

function VolSerialNumber(DriveChar: Char): DWORD; unsafe;varNotUsed: DWORD;VolFlags: DWORD;VolSerNumber: DWORD;Buf: array [0..MAX_PATH] of Char;beginGetVolumeInformation ((PChar(DriveChar + ':\'), Buf, sizeof(Buf), @VolSerNumber, NotUsed, VolFlags, nil, 0));Result := VolSerNumber;end;

please help for error

this code work well in delphi 7 but after upgrade delphi 8 error in GetVolumeInformation ((PChar(DriveChar + ':\'), Buf, sizeof(Buf), @VolSerNumber, NotUsed, VolFlags, nil, 0));

[Error] WinForm.pas(89): Invalid typecast

[Error] WinForm.pas(89): There is no overloaded version of 'GetVolumeInformation' that can be called with these arguments

 

Link to comment
  • Check how many parameters GetVolumeInformation takes in delphi 8.

If there is no problems with number of parameters I suspect that it takes a wide char instead. So change Buff to array of WChar, and use GetVol(PWChar(DriveChar + ':\'). 

Try that and see how it goes. 

Link to comment

Delphi 8 is a really, really horrible .NET-only version. Unless you really must use it, I strongly suggest you to switch to Delphi 10 or Delphi 2007. :)

 

Look how the definition of GetVolumeInformation looks like in D8:

function GetVolumeInformation(lpRootPathName: string; lpVolumeNameBuffer: StringBuilder;  nVolumeNameSize: DWORD; out lpVolumeSerialNumber: DWORD;  out lpMaximumComponentLength, lpFileSystemFlags: DWORD;  lpFileSystemNameBuffer: StringBuilder; nFileSystemNameSize: DWORD): BOOL; overload;function GetVolumeInformation(lpRootPathName: string; lpVolumeNameBuffer: StringBuilder;  nVolumeNameSize: DWORD; lpVolumeSerialNumber: IntPtr;  out lpMaximumComponentLength, lpFileSystemFlags: DWORD;  lpFileSystemNameBuffer: StringBuilder; nFileSystemNameSize: DWORD): BOOL; overload;function GetVolumeInformationA(lpRootPathName: string; lpVolumeNameBuffer: StringBuilder;  nVolumeNameSize: DWORD; out lpVolumeSerialNumber: DWORD;  out lpMaximumComponentLength, lpFileSystemFlags: DWORD;  lpFileSystemNameBuffer: StringBuilder; nFileSystemNameSize: DWORD): BOOL;function GetVolumeInformationW(lpRootPathName: string; lpVolumeNameBuffer: StringBuilder;  nVolumeNameSize: DWORD; out lpVolumeSerialNumber: DWORD;  out lpMaximumComponentLength, lpFileSystemFlags: DWORD;  lpFileSystemNameBuffer: StringBuilder; nFileSystemNameSize: DWORD): BOOL;
lpVolumeNameBuffer is not PChar anymore, you must use StringBuilder instead.
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...