Estoy haciendo una ventana de Acerca de.... y dentro de esa ventana quiero poner algunos detalles sobre el espacio de disco duro.
Tengo este código:
procedure TForm2.Button1Click(Sender: TObject); var lpRoot: PChar; lpFreeBytesToCaller,lpTotalBytes,lpFreeBytes: PLargeInteger; int64Total,int64Free: Int64; begin lpRoot := 'C:\'; if Windows.GetDiskFreeSpaceEx( lpRoot, lpFreeBytesToCaller, lpTotalBytes, lpFreeBytes ) then begin int64Total := int64(lpTotalBytes); int64Free := int64(lpFreeBytes); Memo1.Lines.Add('Espacio Total del Disco: ' + Format('%d',[int64Total])); Memo1.Lines.Add('Espacio Libre del Disco: ' + Format('%d',[int64Free])); end; end;
Pero me muestra el siguiente error:
---------------------------
Debugger Fault Notification
---------------------------
Project C:\Desarrollo\TDelphi\Comun\API MS\Project2.exe faulted with message: 'access violation at 0x00438aff: read of address 0x00000003'. Process Stopped. Use Step or Run to continue.
---------------------------
OK
---------------------------
Debo comentar que además del error que me envía no me muestra los datos correctamente.
También usaba la función Windows.GetDiskFreeSpace la cual no me muestra ningún error sin embargo no me muestran tampoco los datos correctamente.
function EspacioLibreEnDisco( const Drive : char ) : Int64; begin lpRootPathName := PChar( Drive + ':\' ); if Windows.GetDiskFreeSpace( lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters ) then Result := lpNumberOfFreeClusters * lpBytesPerSector * lpSectorsPerCluster else Result := -1; end;
¿Que estoy haciendo mal?
Salud OS