Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Variablen vergleichen (https://www.delphipraxis.net/24601-variablen-vergleichen.html)

sui 23. Jun 2004 14:07


Variablen vergleichen
 
Moin, ich hab in der Delphi-Hilfe den Code zum auslesen der Festplattengrösse gefunden
und ein klein wenig geändert. Klappt auch alles wunderbar, aber am Ende soll geprüft werden
ob mehr als ein Gigabyte frei ist, wenn nicht soll in label3 eine Meldung ausgegeben werden.

Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  platz: string;
  prozent: string;
  partition: Int64;
  total:  Int64;
begin
  partition := DiskFree(4);
  total := DiskSize(4);

  prozent := IntToStr
  (100 * partition div total) + 'Prozent frei: ';
  label1.caption := prozent;

  platz := Inttostr
  (partition div 1024 div 1024 div 1024) + ' Gbytes frei. ' ;
  Label2.Caption := platz;

  if platz < 1 then label3.Caption := 'Platte aufräumen';


end;
Jetzt klappt das vergleichen aber nicht!!! :gruebel:

Gruss

Phoenix 23. Jun 2004 14:12

Re: Variablen vergleichen
 
Platz ist ein String, also eine Zeichenkette.
1 ist aber eine Zahl.

Du müsstest also schon:
Code:
if StringToFloat(Platz) < 1 then
nehmen.

Muetze1 23. Jun 2004 14:15

Re: Variablen vergleichen
 
Moin!

Oder nicht die Zahl in einen String um ihn dann für den Vergleich wieder zurück umzuwandeln, sondern nur dort umwandeln wo es nötig ist.

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  platz: Int64;
  prozent: string;
  partition: Int64;
  total:  Int64;
begin
  partition := DiskFree(4);
  total := DiskSize(4);

  prozent := IntToStr
  (100 * partition div total) + 'Prozent frei: ';
  label1.caption := prozent;

  platz := partition div 1024 div 1024 div 1024;
  Label2.Caption := IntToStr(platz) +  ' Gbytes frei. ' ;

  if platz < 1 then label3.Caption := 'Platte aufräumen';


end;
MfG
Muetze1

sui 23. Jun 2004 15:32

Re: Variablen vergleichen
 
Danke, das erste Beipiel klappt nicht, vielleicht hab ich auch was falsch gemacht.

Die 2. Lösung haut hin, leuchtet mir auch ein, also Problem gelöst. :hello:


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:13 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz