
13-10-2016, 12:55
|
|
Registered User
|
|
Join Date: Oct 2016
Location: china
Posts: 10
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by JRD!
Certainly the improved:
Code:
#ifdef UNICODE
#define AW "W"
#else
#define AW "A"
#endif
type
TDiskInfo = record
DriveRoot: string;
FreeSpace: cardinal;
TotalSpace: cardinal;
end;
TDiskInfos = array of TDiskInfo;
function GetDriveType(lpRootPathName: string): UINT;
external 'GetDriveType{#AW}@kernel32.dll stdcall';
function GetLogicalDriveStrings(nBufferLength: DWORD; lpBuffer: string): DWORD;
external 'GetLogicalDriveStrings{#AW}@kernel32.dll stdcall';
Function GetMaxFreeSpace(Value: String): String;
var
S: String;
I, J: Integer;
DiskInfos: TDiskInfos;
begin
I := 0; J:=0;
if GetLogicalDriveStrings(0, #0) > 0 then
begin
SetLength(S, GetLogicalDriveStrings(0, #0));
if GetLogicalDriveStrings(Length(S), S) > 0 then
begin
S := TrimRight(S) + #0;
while Pos(#0, S) > 0 do
begin
if (GetDriveType(Copy(S, 1, Pos(#0, S) - 1)) = 3) then
begin
Inc(I);
SetLength(DiskInfos, I);
DiskInfos[I-1].DriveRoot:=Copy(S, 1, Pos(#0, S) - 1);
GetSpaceOnDisk(DiskInfos[I-1].DriveRoot, True, DiskInfos[I-1].FreeSpace, DiskInfos[I-1].TotalSpace);
end;
Delete(S, 1, Pos(#0, S));
end;
for I := 0 to Length(DiskInfos) -1 do
begin
if I = 0 then
J := DiskInfos[i].FreeSpace else
begin
if J > DiskInfos[i].FreeSpace then J := J else
begin
J := DiskInfos[i].FreeSpace;
Result:=DiskInfos[i].DriveRoot;
end;
end;
end;
end;
end;
end;
|
What is this error?
why?
|