Delphi-PRAXiS
Seite 3 von 4     123 4      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi zahl in Uhrzeit darstellen (https://www.delphipraxis.net/72877-zahl-uhrzeit-darstellen.html)

Cr3at0r 12. Jul 2006 18:58

Re: zahl in Uhrzeit darstellen
 
also ich hatte genau deine function vor die procedure gesetzt.

nur find ich da irgendwie keinen fehler, nochma alles:

Delphi-Quellcode:
function SecToStr (sec: Int64): string;

var

  DT : TDateTime;

begin
  DT := sec / (60 * 60 * 24);

  Result := IntToStr(Trunc(DT)) + ' Tage';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
prodiri, prodhol, prodo2, wk, hol, o2, iri, bbt: real;
iri2, hol2, o22, iri3, hol3, o23: real;
iritag, holtag, o2tag: real;
iristd, holstd, o2std: real;
iriv, irib, holv, holb, o2v, o2b: real;
irig: real;

begin
prodiri := strtofloat(edit1.Text);
prodhol := strtofloat(edit4.text);
prodo2 := strtofloat(edit5.text);
bbt := strtofloat(edit2.text);
wk := strtofloat(edit3.text);

iri := (10 * (1 + (Power(prodiri,1.9))));
hol := (10 * (1 + (Power(prodhol,1.8))));
o2 := (10 * (Power(prodo2,2)));

iri2 := iri * (Power(1 + 5/100, bbt));
hol2 := hol * (Power(1 + 5/100, bbt));
o22 := o2 * (Power(1 + 5/100,wk) * (20/70));


label1.Caption := floattostr(iri2);
label2.Caption := floattostr(hol2);
label4.Caption := floattostr(o22);

iritag := iri2 * 24;
holtag := hol2 * 24;
o2tag := o22 * 24;

label10.caption := floattostr(iritag);
label11.caption := floattostr(holtag);
label12.caption := floattostr(o2tag);

iristd := strtofloat(edit6.text) * iri2;
holstd := strtofloat(edit6.text) * hol2;
o2std := strtofloat(edit6.text) * o22;

label19.Caption := floattostr(iristd);
label20.Caption := floattostr(holstd);
label21.Caption := floattostr(o2std);

iriv := strtofloat(edit7.text);
irib := strtofloat(edit8.text);
holv := strtofloat(edit9.text);
holb := strtofloat(edit10.text);
o2v := strtofloat(edit11.text);
o2b := strtofloat(edit12.text);

irig := floattosec((irib - iriv) / iri2);

label51.caption := sectostr(irig);


end;

Michael Habbe 12. Jul 2006 20:28

Re: zahl in Uhrzeit darstellen
 
Zitat:

Zitat von Cr3at0r
nur find ich da irgendwie keinen fehler, nochma alles:
Delphi-Quellcode:
...
irig := floattosec((irib - iriv) / iri2);
...

:gruebel: Es gibt in Delphi keine Funktion "floattosec", die musst Du selbst programmieren.

Cr3at0r 12. Jul 2006 20:34

Re: zahl in Uhrzeit darstellen
 
ok dann weiß ich schonma wie das mit dem aufrufen der function geht aber jetzt hab ich das entfernt nun hab ich in dieser zeile:

Delphi-Quellcode:
label51.caption := SectoStr(irig);
den fehler:
[Fehler] ets_res_prod2.pas(174): E2010 Inkompatible Typen: 'Int64' und 'Real'

Liegt es damit zu sammen das ich irig als real deklariert hab und der rückgabewert in int64 ist?

Nils_13 12. Jul 2006 20:38

Re: zahl in Uhrzeit darstellen
 
Du brauchst jetzt die Funktionen zum Konvertieren:
FloatToStr
StrToFloat
IntToStr
StrToInt
FloatToStr
StrToFloat
usw.

Float = Real
Int = Integer

steht alles in der Hilfe.

Cr3at0r 12. Jul 2006 20:41

Re: zahl in Uhrzeit darstellen
 
nur das doofe ist ja das es keine ganzzahligen zahlen sind und integer nur ganzzahlige beeinhaltet.

Im mom hab ich keine Ahnung wie ich das machn könnte

Michael Habbe 13. Jul 2006 00:16

Re: zahl in Uhrzeit darstellen
 
Zitat:

Zitat von Cr3at0r
nur das doofe ist ja das es keine ganzzahligen zahlen sind und integer nur ganzzahlige beeinhaltet.
Im mom hab ich keine Ahnung wie ich das machn könnte

Na, dann lies Dich mal ein wenig in der Hilfe zu den Datentypen schlau und ändere anschließend den Header der Funktion ab:
Delphi-Quellcode:
function SecToStr (sec: Int64): string;
function SecToStr (sec: Double): string;
mfg

Luckie 13. Jul 2006 02:01

Re: zahl in Uhrzeit darstellen
 
Zitat:

Zitat von Jelly
Also Luckie, von deiner langen Funktion bin ich jetzt etwas überrascht... Ich würd das in einen 2-Zeiler packen :mrgreen:

Kommt daher, weil Olli auf die SysUtils verzichtet hat.

Cr3at0r 13. Jul 2006 11:10

Re: zahl in Uhrzeit darstellen
 
hmmm :shock: :shock: :shock: :shock: :shock: :shock:
blicke da nicht durch.

Also der rückgabewert der function ist als string deklariert richtig?

Dann muss ich doch irig auch als string deklarieren seh ich das richtig?

Hab jetzt einfach ma irig als string deklaerier habe aber dann in der letzten zeile noch einen Fehler:
"[Fehler] ets_res_prod2.pas(174): E2010 Inkompatible Typen: 'Int64' und 'string'"

Demnach wäre der rückgabewert int64 jetzt meine frage wie mach ich des denn richtig?

himitsu 13. Jul 2006 11:38

Re: zahl in Uhrzeit darstellen
 
Zeig man die QuellCodeZeile zu dieser Fehlermeldung.


PS: der Fehler könnte auch gut bei einem anderem Parameter liegen ... also wenn das mit dem String jetzt stimmt ;)

DennisHB 13. Jul 2006 11:56

Re: zahl in Uhrzeit darstellen
 
Unit: System

Description:
The Trunc function truncates a real-type value to an integer-type value. X is a real-type expression. Trunc returns an Int64 value that is the value of X rounded toward zero.

If the truncated value of X is not within the Int64 range, an EInvalidOp exception is raised.

Delphi-Quellcode:
...
label51.caption := sectostr(Trunc(irig));
...


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:46 Uhr.
Seite 3 von 4     123 4      

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