SRL Archive - SRL Archives

function StrToFloatDef(s: string; def: extended): string;


Wanted

2007-06-10 16:57:03

function StrToFloatDef(s: string; def: extended): extended;
begin
try
Result := StrToFloat(s);
except
Result := def;
end;
end;

function StrToBoolDef(s: string; def: boolean): boolean;
begin
try
Result := StrToBool(s);
except
Result := def;
end;
end;

Edit: Also anything that is a string conversion should have a default… there's a lot more in ArrayLoader.scar in SRL

Pentti

2007-06-10 17:12:09

Nice, but shouldn't it be:

try
Result:=StrToBool(s);
except
Result := def;

  try
Result:=StrToFloat(s);
except
Result := def;
end;

Wanted

2007-06-10 17:14:33

Yes, I changed it right after I posted. I guess you didn't refresh in time :(

Bobarkinator

2007-06-10 19:24:56

Lol I thought I would never use a StrToBool but I did a few days ago.

Wanted

2007-06-11 15:56:16

Yea It's pretty useful when it comes to loading data files or saved settings.

n3ss3s

2007-06-20 09:05:37

YUp