Autor |
Beitrag |
MaRiO
      
Beiträge: 20
Windows XP
D7 Prof.
|
Verfasst: Di 11.11.03 12:02
Hallo @all.
Ich stelle mich gerade blöd an, komme aber nicht auf die Lösung wie Ich den Wert aus dieser Funktion :
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
| function GetDiskSize(drive: Char; var free_size, total_size: Int64): Boolean; var RootPath: array[0..4] of Char; RootPtr: PChar; current_dir: string; begin RootPath[0] := Drive; RootPath[1] := ':'; RootPath[2] := '\'; RootPath[3] := #0; RootPtr := RootPath; current_dir := GetCurrentDir; if SetCurrentDir(drive + ':\') then begin GetDiskFreeSpaceEx(RootPtr, Free_size, Total_size, nil); SetCurrentDir(current_dir); Result := True; end else begin Result := False; Free_size := -1; Total_size := -1; end; end; |
Z.b. Als Mega Byte, Kilobyte usw. ausgeben kann. Bei mir steht in der Variable Groesse z.b. 352663774
Ich möchte diesen Wert gerne Umrechnen. Kann mir gerade jemand Helfen ?
Mfg
Mario
Moderiert von Tino: Code- durch Delphi-Tags ersetzt.
_________________ Application.MessageBox('Delphi ist Cool', 'Delphi 7', 1);
|
|
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Di 11.11.03 12:15
Wie viel Byte hat denn ein Kilobyte und wie viel Kilobyte hat ein Megabyte? 
|
|
MaRiO 
      
Beiträge: 20
Windows XP
D7 Prof.
|
Verfasst: Di 11.11.03 12:40
Ist mir schon klar :
1 KB = 1024 Byte.
1 MB = 1024 KB.
Habe meine Frage vieleicht nicht richtig gestellt.
Ich möchte gerne einen Rückgabewert in einem String der mir das KB,MB,GB oder Byte hinten dran packt.
Verstehst du was Ich meine ?
MFG
Mario
_________________ Application.MessageBox('Delphi ist Cool', 'Delphi 7', 1);
|
|
MaRiO 
      
Beiträge: 20
Windows XP
D7 Prof.
|
Verfasst: Di 11.11.03 12:45
Ich poste dir mal meinen Quelltext, ist aber warscheinlich Unsinnig und Falsch.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34:
| GetDiskSize('G', free_size, total_size); differenz :=total_size - free_size;
dif :=FloatToStr(differenz / 1048576);
IF Length(dif) > 12 Then Dif := dif + ' TB'; IF Length(dif) = 8 Then Dif := dif + ' GB'; IF Length(dif) = 5 Then Dif := Dif + ' MB'; IF Length(dif) < 5 Then Dif := Dif + ' KB';
frei :=FloatToStr(free_size div 1024); IF Length(frei) >= 12 Then Begin frei :=FloatToStr(free_size / sqr(1024)); frei := frei + ' TB'; End Else Begin IF (Length(frei) <= 12) and (Length(frei) > 7) Then Begin frei :=FloatToStr(free_size / sqr(1024)); frei := frei + ' GB'; End Else Begin IF (Length(frei) <= 8) and (Length(frei) >5) Then Begin frei :=FloatToStr(free_size / sqr(1024)); frei := frei + ' MB'; End Else Begin IF (Length(frei) <= 5) Then Begin frei :=FloatToStr(free_size div 1024); frei := frei + ' KB'; End Else Begin IF Length(frei) <= 5 Then groesselwg :='Speicher kleiner 1 MB'; fehler :=groesselwg; End; End; End; ShowMessage(frei); End; |
Moderiert von Tino: Quote- durch Delphi-Tags ersetzt.
_________________ Application.MessageBox('Delphi ist Cool', 'Delphi 7', 1);
|
|
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Di 11.11.03 13:28
Wie wäre es hiermit:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10:
| function FormatDiskSpace(DiskSpace: Int64): string; begin case DiskSpace of 0..1023: result := Format('%d byte', [DiskSpace]); 1024..1048576: result := Format('%2n KB', [DiskSpace / 1024]); 1048577..1073741824: result := Format('%2n MB', [DiskSpace / 1024 / 1024]); else result := Format('%2n GB', [DiskSpace / 1024 / 1024 / 1024]); end; end; |
|
|
smiegel
      
Beiträge: 992
Erhaltene Danke: 1
WIN 7
D7 Prof., C#, RAD XE Prof.
|
Verfasst: Di 11.11.03 13:49
Hallo,
oder so:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
| const iKByte=1024; iMByte=1024*iKByte; iGByte=1024*iMByte;
type TByteFormat(bf_Byte, bf_KByte, bf_MByte, bf_GByte);
function FormatByte(const aSize:Extended; aFmt:TByteFormat):String; begin case aFmt of bf_Byte :Result:=FormatFloat(aSize, '#,#0 Byte'); bf_KByte:Result:=FormatFloat(aSize/iKByte, '#,#0.00 KB'); bf_MByte:Result:=FormatFloat(aSize/iMByte, '#,#0.00 MB'); bf_GByte:Result:=FormatFloat(aSize/iGByte, '#,#0.00 GB'); else Result:=FormatFloat(aSize, '#,#0 Byte'); end; end; ... ... Label1.Caption:='Frei: '+FormatByte(free_size, bf_MGyte); Label2.Caption:='Belegt: '+FormatByte(total_size-free_size, bf_MByte); ... |
_________________ Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
|
|
MaRiO 
      
Beiträge: 20
Windows XP
D7 Prof.
|
Verfasst: Di 11.11.03 14:38
Super gemacht ! Danke an alle Beteiligten.
Werde mal versuchen zu verstehen.
Mfg
Mario
_________________ Application.MessageBox('Delphi ist Cool', 'Delphi 7', 1);
|
|
|