Dzielenie liczby w delphi

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;)

Czemu to nie działa?

WD := IntToStr(FindFilesSize(Value, '*.*', True));

      Funkcja1 := WD / 1024;

No a po co dajesz to inttostr?

wd to wielkość w bajtach? Jak tak to po co to zapisujesz do stringu? Zmień to na int i będzie działać

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.

Incompatible types: ‘Integer’ and ‘Extended’ xD

Ehh ja się dobrze na delphi nie znam bo mnie te typy zawsze osłabiały :slight_smile:

Masz tu cos:

http://www.pixel2life.com/forums/index. … opic=34076

EDIT:

y := Round(wd); i bedziesz miał wynik zaokraglony

i wtedy dajesz wynik := y / 1024

Albo zamiast dzielenia / dac div (dzielenie na calość).

wynik := y div 1024;

albo należy zacząć czytać błędy ze zrozumieniem :wink:

błąd typu:

"Incompatible types: ‘String’ and ‘Integer’ " jest chyba jasny? zwłaszcza że masz jeszcze podaną linię w której on występuje…

jeśli na początku nie zacznie się ‘czytać’ błędów, to potem łatwiej nie będzie…