Autor Beitrag
bflegel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 193
Erhaltene Danke: 1

Win XP, Win 7, BS2000
D5
BeitragVerfasst: Mi 19.03.08 17:55 
Hallo,

ich benutze Delphi 5 und dort gibt es den Befehl StrToFloatDef -anscheinend- noch nicht. Nun gut sage ich mir, machste es halt selbst.

Gesagt, getan:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function StrToFloatDef (string_ein : string, default : extended) : extended;
begin
  try
    result := StrToFloat(string_ein);
  except
    result := default;
  end;
end;


Funktioniert auch soweit.

Aber nun zu meiner Frage:

Kann ich im Functions-Kopf den Wert default auch vorbelegen, so dass ich mir den Default-Wert auch sparen kann?

z.B.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function StrToFloatDef (string_ein : string, default : extended = 0) : extended;
begin
...
end;

// Aufruf

zahl := StrToFloatDef(Edit1.Text);


Die SuFu brachte mich nicht weiter (vielleicht hab ich auch nur die falschen Suchbegriffe :nixweiss: )

_________________
I know all the jokes about my name
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Mi 19.03.08 18:02 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function StrToFloatDef (string_ein : string; default : extended = 0) : extended;
begin
  try
    result := StrToFloat(string_ein);
  except
    result := default;
  end;
end;


Manche Sachen Sind so einfach... :D

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
bflegel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 193
Erhaltene Danke: 1

Win XP, Win 7, BS2000
D5
BeitragVerfasst: Mi 19.03.08 18:10 
Grmpf,

ich hatte zuerst das Komma drin, und Delphi hat gemotzt. Als erstes dachte ich die Zuweisung geht nicht und hab sie rausgenommen. Erst danach hab ich den Strichpunkt eingesetzt und nicht mehr '= 0' getestet.

Den Quelltext hatte ich aus dem Kopf getippt und wieder das Komma eingesetzt :oops:

Danke für Deine Hilfe.

bye
bflegel

_________________
I know all the jokes about my name