Raise EConvertError in TFormMain.LoadSettings when getting value 'temperature'
ziv2015 opened this issue · 2 comments
Raise EConvertError in TFormMain.LoadSettings when getting 'temperature' value
The reason for this is that saving to jeson uses TFormatSettings.Invariant, while loading uses local settings.
If they are different, this error occurs. Solution to the problem:
procedure TFormMain.LoadSettings;
var LTemperature : string;
begin
try
if not TFile.Exists(GetSettingsFileName) then
Exit;
var JsonText: string := '';
try
JsonText := TFile.ReadAllText(GetSettingsFileName, TEncoding.UTF8);
except
Exit;
end;
if JsonText.IsEmpty then
Exit;
var JSON := TJSONObject.ParseJSONValue(JsonText);
if Assigned(JSON) then
try
Token := JSON.GetValue('api_key', '');
//Temperature := JSON.GetValue('temperature', 0); //<-- EConvertError here
LTemperature := Json.GetValue('temperature', '0');
Temperature := StrToFloat(LTemperature, TFormatSettings.Invariant);
Lang := JSON.GetValue('translate_lang', '');
FSelectedChatId := JSON.GetValue('selected_chat', '');
finally
JSON.Free;
end;
finally
if Token.IsEmpty then
OpenSettings;
end;
end;
There need to specify the type of the generic method. I'll fix it in a couple of hours
Fixed