让俺来给你抄一个例子:
AppServer:
procedure TSystemHelp.DriveInfo(out TotalCount: Integer;
out DriveInfo: Variant);
const
Size = 28 * 5;
// 26 letters times plenty of room for letters
var
DriveStrings, TempDriveStrings: PChar;
DriveType: string;
SectorsPerCluster, BytesPerSector: Cardinal;
NumberOfFreeClusters, TotalNumberOfClusters: Cardinal;
FreeAvailable, TotalSpace: LargeInt;
TotalFree: LargeInt;
DriveInfoRec: TDriveInfoRec;
ADrive: Variant;
TempVar: Variant;
TempPtr: Pointer;
begin
TotalCount := 0;
DriveInfo := VarArrayCreate([0, 28], VarVariant);
GetMem(DriveStrings, Size);
GetLogicalDriveStrings(Size, DriveStrings);
TempDriveStrings := DriveStrings;
while StrLen(TempDriveStrings) <> 0do
begin
ADrive := VarArrayCreate([0, 3], VarVariant);
case GetDriveType(TempDriveStrings) of
DRIVE_UNKNOWN: DriveType := 'Unknown';
DRIVE_NO_ROOT_DIR: DriveType := 'Not a root drive';
DRIVE_REMOVABLE: DriveType := 'Removable';
DRIVE_FIXED: DriveType := 'Hard Drive';
DRIVE_REMOTE: DriveType := 'Network';
DRIVE_CDROM: DriveType := 'CDROM';
DRIVE_RAMDISK: DriveType := 'RAMDisk';
else
DriveType := 'Error';
end;
ADrive[0] := AnsiString(TempDriveStrings);
ADrive[1] := DriveType;
GetDiskFreeSpace(TempDriveStrings, SectorsPerCluster, BytesPerSector,
NumberOfFreeClusters, TotalNumberOfClusters);
DriveInfoRec.SectorsPerCluster := SectorsPerCluster;
DriveInfoRec.BytesPerSector := BytesPerSector;
DriveInfoRec.NumberOfFreeClusters := NumberOfFreeClusters;
DriveInfoRec.TotalNumberOfClusters := TotalNumberOfClusters;
GetDiskFreeSpaceEx(TempDriveStrings, FreeAvailable, TotalSpace, @TotalFree);
DriveInfoRec.FreeAvailable := FreeAvailable;
DriveInfoRec.TotalSpace := TotalSpace;
DriveInfoRec.TotalFree := TotalFree;
TempVar := VarArrayCreate([0, SizeOf(TDriveInfoRec)], VarByte);
TempPtr := VarArrayLock(TempVar);
Move(DriveInfoRec, TempPtr^, SizeOf(TDriveInfoRec));
VarArrayUnlock(TempVar);
ADrive[2] := TempVar;
DriveInfo[TotalCount] := ADrive;
Inc(TempDriveStrings, StrLen(TempDriveStrings) + 1);
Inc(TotalCount);
end;
FreeMem(DriveStrings, Size);
end;
Client:
procedure TForm1.ReportOnDriveStatus;
const
Size = 28 * 5;
// 26 letters plus A and B times plenty of room for letters
var
TotalCount, i: Integer;
ADrive, DriveInfo: Variant;
DriveInfoRec: TDriveInfoRec;
TempVar: Variant;
TempPtr: Pointer;
begin
if FSystemHelp = nil then
Exit
else
FSystemHelp.DriveInfo(TotalCount, DriveInfo);
Memo1.Clear;
for i := 0 to TotalCount - 1do
begin
ADrive := DriveInfo;
Memo1.Lines.Add('[' + ADrive[0] + '] ' + ADrive[1]);
TempVar := ADrive[2];
TempPtr := VarArrayLock(TempVar);
Move(TempPtr^, DriveInfoRec, SizeOf(TDriveInfoRec));
with Memo1.Lines, DriveInfoRecdo
begin
Memo1.Lines.Add('Sectors Per Cluster: ' + IntToStr(SectorsPerCluster));
Memo1.Lines.Add('Bytes Per Sector: ' + IntToStr(BytesPerSector));
Memo1.Lines.Add('Number of Free Clusters: ' +
IntToStr(NumberOfFreeClusters));
Memo1.Lines.Add('Total Number of Clusters: ' +
IntToStr(TotalNumberOfClusters));
Memo1.Lines.Add('Free Avalable: ' + IntToStr(FreeAvailable));
Memo1.Lines.Add('Total Space: ' + IntToStr(TotalSpace));
Memo1.Lines.Add('Total Free: ' + IntToStr(TotalFree));
Memo1.Lines.Add('');
end;
end;
end;