Einzelnen Beitrag anzeigen

Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.024 Beiträge
 
Delphi 12 Athens
 
#8

AW: "Sicheres" Umwandeln von Zeichenkette in Zahl

  Alt 29. Sep 2017, 10:30
Um meinen Vorschlag mal zu konkretisieren (hoffe mal, das geht alles unter D2006):
Delphi-Quellcode:
var
  AllFormatSettings: array of TFormatSettings;

procedure InitFormatSettings;
const
  cLocales: array[0..5] of Integer
      = (
         1031, { German }
         1033, { English }
         1040, { Italian }
         1055, { Turkish }
         3082, { Spanish }
         LOCALE_USER_DEFAULT);
var
  I: Integer;

begin
  SetLength(AllFormatSettings, Length(cLocales));
  for I := 0 to Length(cLocales) - 1 do begin
    GetLocaleFormatSettings(cLocales[I], AllFormatSettings[I]);
  end;
end;

function TryStrToFloatAll(const S: string; out Value: Double): Boolean;
var
  I: Integer;
begin
  Result := True;
  for I := 0 to Length(AllFormatSettings) - 1 do begin
    if TryStrToFloat(S, Value, AllFormatSettings[I]) then Exit;
  end;
  Result := False;
end;
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat