Endelig ferdig.. Hær kommer diskplass-uniten på nytt:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetFreeDiskSpace(Drive: PChar): Int64;
var
BytesPerCluster,
SectorsPerCluster,
BytesPerSector,
NumberOfFreeClusters,
TotalNumberOfClusters,
FreeDiskSpace: DWORD;
begin
if GetDiskFreeSpace(Drive, SectorsPerCluster,
BytesPerSector,
NumberOfFreeClusters,
TotalNumberOfClusters) then
begin
BytesPerCluster := SectorsPerCluster * BytesPerSector;
FreeDiskSpace := BytesPerCluster * NumberOfFreeClusters;
Result := FreeDiskSpace;
end
else
Result := -1;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
FileName = 'filnavn.exe';
var
FreeDiskSpace,
ReqDiskSpace: Int64;
FreeDiskSpaceMBStr,
ReqDiskSpaceKBStr,
ReqDiskSpaceMBStr: String;
ReqDiskSpaceKB: Integer;
CheckFreeSpaceDrive: PChar;
// KUN for binære filer (*.exe *.zip osv
// Bruk F: TextFile; for tekstfiler
F: File of Byte;
begin
CheckFreeSpaceDrive := 'C:';
FreeDiskSpace := GetFreeDiskSpace(CheckFreeSpaceDrive);
FreeDiskSpaceMBStr := Format('%2.2f', [FreeDiskSpace / 1024 / 1024]);
if FreeDiskSpace <> -1 then
begin
if FileExists(FileName) then
begin
AssignFile(F, FileName);
Reset(F);
ReqDiskSpace := FileSize(F);
CloseFile(F);
ReqDiskSpaceKB := ReqDiskSpace div 1024;
ReqDiskSpaceKBStr := Format('%2.1f', [ReqDiskSpace / 1024]);
ReqDiskSpaceMBStr := Format('%2.2f', [ReqDiskSpace / 1024 / 1024]);
if ReqDiskSpace = FreeDiskSpace then
// kjør programmet.
else
begin
if ReqDiskSpaceKB < 1024 then // Sjekker om ReqDiskSpace er mindre enn 1MB
MessageBox(Handle, PChar('This program requires ' + ReqDiskSpaceKBStr +
'kB. Drive ' + CheckFreeSpaceDrive + ' has ' + FreeDiskSpaceMBStr +
'MB free space!'),
'ERROR', MB_ICONERROR)
else
if ReqDiskSpaceKB >= 1024 then // Sjekker om ReqDiskSpace er større eller det samme som 1MB
MessageBox(Handle, PChar('This program requires ' + ReqDiskSpaceMBStr +
'MB. Drive ' + CheckFreeSpaceDrive + ' has ' + FreeDiskSpaceMBStr +
'MB free space!'),
'ERROR', MB_ICONERROR)
end;
end
else
MessageBox(Handle, PChar('The file "' + FileName + '" does not exist!'), 'ERROR', MB_ICONERROR);
end
else
MessageBox(Handle, PChar('Drive ' + CheckFreeSpaceDrive + ' does not exist!'), 'ERROR', MB_ICONERROR);
end;
end.
Hvis det skulle være noe, så bare spør.
DiZpel
[Redigeret d. 09/02-04 13:31:21 af DiZpel]