Witam. Mam problem z funkcją dzielenia. Otóż tak: Program mi czyta rozmiar całego folderu i podfolderów, ale wynik podaje mi w bajtach. Dlatego też ja chcę wynik podzielić podwójnie przez 1024 aby wynik został wyświetlony w MB.
procedure TForm1.FormCreate(Sender: TObject);
var
Value : String;
WD : String;
Funkcja1 : Integer;
Funkcja2 : Integer;
function FindFilesSize(const Path, Mask: string; IncludeSubDir: boolean): integer;
var
FindResult : integer;
SearchRec : TSearchRec;
begin
result := 0;
FindResult := FindFirst(Path + Mask, faAnyFile - faDirectory, SearchRec);
while FindResult = 0 do
begin
Result := Result + SearchRec.Size;
FindResult := FindNext(SearchRec);
end;
FindClose(SearchRec);
if not IncludeSubDir then
Exit;
FindResult := FindFirst(Path + '*.*', faDirectory, SearchRec);
while FindResult = 0 do
begin
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
Result := Result + FindFilesSize(Path + SearchRec.Name + '\', Mask, True);
FindResult := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
begin
WD := IntToStr(FindFilesSize(Value, '*.*', True));
Funkcja1 := WD / 1024;
Funkcja2 := Funkcja1 / 1024;
Panel5.Caption := Funkcja2;
end;
Niestety problem tkwi w tym, że wyskakuje błąd podczas kompilacji o treści "Incompatible types: ‘String’ and ‘Integer’ " (Funkcja1 := WD / 1024;)
Teraz też nie działa ale za to błąd jest innej treści…
procedure TForm1.FormCreate(Sender: TObject);
var
Value : String;
WD : Integer;
Funkcja1 : Integer;
Funkcja2 : Integer;
function FindFilesSize(const Path, Mask: string; IncludeSubDir: boolean): integer;
var
FindResult : integer;
SearchRec : TSearchRec;
begin
result := 0;
FindResult := FindFirst(Path + Mask, faAnyFile - faDirectory, SearchRec);
while FindResult = 0 do
begin
Result := Result + SearchRec.Size;
FindResult := FindNext(SearchRec);
end;
FindClose(SearchRec);
if not IncludeSubDir then
Exit;
FindResult := FindFirst(Path + '*.*', faDirectory, SearchRec);
while FindResult = 0 do
begin
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
Result := Result + FindFilesSize(Path + SearchRec.Name + '\', Mask, True);
FindResult := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
begin
{troche kodu usunolem bo on jest od czegos innego}
WD := (FindFilesSize(Value, '*.*', True));
Funkcja1 := WD / 1024;
Funkcja2 := Funkcja1 / 1024;
Panel5.Caption := Funkcja2;
end;
Panel6.Caption := IntToStr(FindFIles(Value, '*.bsp', True));
end;
end.