Skip to content

Commit

Permalink
Merge pull request #2 from JensBorrisholt/Issue-out-of-memory
Browse files Browse the repository at this point in the history
Issue: Out of memory error and High CPU usage
  • Loading branch information
JensBorrisholt authored Mar 28, 2021
2 parents 0777630 + 601fb67 commit 51c4031
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions Generator GUI/MainFormU.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ object MainForm: TMainForm
'"'
''
'See also the possibilities in the MenuBar')
OnChangeTracking = MemoJSONChangeTracking
Align = Client
Size.Width = 613.000000000000000000
Size.Height = 355.000000000000000000
Expand Down
16 changes: 15 additions & 1 deletion Generator GUI/MainFormU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ TMainForm = class(TForm)
procedure Label1Click(Sender: TObject);
procedure ActionList1Update(Action: TBasicAction; var Handled: Boolean);
procedure EditClassNameChange(Sender: TObject);
procedure MemoJSONChangeTracking(Sender: TObject);
private type
TValidationTypes = (vtUnchecked, vtValid, vtInvalid);
private
{ Private declarations }
FCheckVersionResponse: TRelease;
FJsonMapper: TPkgJsonMapper;
FIsValid: TValidationTypes;
public
{ Public declarations }
end;
Expand Down Expand Up @@ -211,10 +215,20 @@ procedure TMainForm.ActionList1Update(Action: TBasicAction; var Handled: Boolean
if not OutputFormatDict.TryGetValue(TabControl1.ActiveTab, OutputFormat) then
OutputFormat := nil;

actConvert.Enabled := FJsonMapper.IsValid(MemoJSON.Text.Trim);
if FIsValid = vtUnchecked then
if FJsonMapper.IsValid(MemoJSON.Text.Trim) then
FIsValid := vtValid
else
FIsValid := vtInvalid;
actConvert.Enabled := FIsValid = vtValid;
actSaveAs.Enabled := (OutputFormat <> nil) and (actConvert.Enabled);
end;

procedure TMainForm.MemoJSONChangeTracking(Sender: TObject);
begin
FIsValid := vtUnchecked;
end;

procedure TMainForm.actOnlineValidationExecute(Sender: TObject);
const
JsonValidatorUrl = 'https://jsonformatter.curiousconcept.com/?data=%s&process=true';
Expand Down
7 changes: 6 additions & 1 deletion Lib/Pkg.Json.Mapper.pas
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,13 @@ function TPkgJsonMapper.GetJsonType(aJsonValue: TJsonValue): TJsonType;
end;

function TPkgJsonMapper.IsValid(aJsonString: string): boolean;
var
Value: TJSONValue;
begin
Result := TJSONObject.ParseJSONValue(aJsonString) <> nil;
Value := TJSONObject.ParseJSONValue(aJsonString);
Result := Value <> nil;
if Result then
Value.Free;
end;

function TPkgJsonMapper.LoadFormFile(aJsonFile: string): TPkgJsonMapper;
Expand Down

0 comments on commit 51c4031

Please sign in to comment.