Einzelnen Beitrag anzeigen

stifflersmom

Registriert seit: 8. Dez 2005
Ort: 24994 Holt
374 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#11

AW: "Sicheres" Umwandeln von Zeichenkette in Zahl

  Alt 29. Sep 2017, 15:06
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;
das werde ich gleich mal ausprobieren.
  Mit Zitat antworten Zitat