Skip to content

Commit 51c4031

Browse files
Merge pull request #2 from JensBorrisholt/Issue-out-of-memory
Issue: Out of memory error and High CPU usage
2 parents 0777630 + 601fb67 commit 51c4031

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Generator GUI/MainFormU.fmx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ object MainForm: TMainForm
123123
'"'
124124
''
125125
'See also the possibilities in the MenuBar')
126+
OnChangeTracking = MemoJSONChangeTracking
126127
Align = Client
127128
Size.Width = 613.000000000000000000
128129
Size.Height = 355.000000000000000000

Generator GUI/MainFormU.pas

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ TMainForm = class(TForm)
7474
procedure Label1Click(Sender: TObject);
7575
procedure ActionList1Update(Action: TBasicAction; var Handled: Boolean);
7676
procedure EditClassNameChange(Sender: TObject);
77+
procedure MemoJSONChangeTracking(Sender: TObject);
78+
private type
79+
TValidationTypes = (vtUnchecked, vtValid, vtInvalid);
7780
private
7881
{ Private declarations }
7982
FCheckVersionResponse: TRelease;
8083
FJsonMapper: TPkgJsonMapper;
84+
FIsValid: TValidationTypes;
8185
public
8286
{ Public declarations }
8387
end;
@@ -211,10 +215,20 @@ procedure TMainForm.ActionList1Update(Action: TBasicAction; var Handled: Boolean
211215
if not OutputFormatDict.TryGetValue(TabControl1.ActiveTab, OutputFormat) then
212216
OutputFormat := nil;
213217

214-
actConvert.Enabled := FJsonMapper.IsValid(MemoJSON.Text.Trim);
218+
if FIsValid = vtUnchecked then
219+
if FJsonMapper.IsValid(MemoJSON.Text.Trim) then
220+
FIsValid := vtValid
221+
else
222+
FIsValid := vtInvalid;
223+
actConvert.Enabled := FIsValid = vtValid;
215224
actSaveAs.Enabled := (OutputFormat <> nil) and (actConvert.Enabled);
216225
end;
217226

227+
procedure TMainForm.MemoJSONChangeTracking(Sender: TObject);
228+
begin
229+
FIsValid := vtUnchecked;
230+
end;
231+
218232
procedure TMainForm.actOnlineValidationExecute(Sender: TObject);
219233
const
220234
JsonValidatorUrl = 'https://jsonformatter.curiousconcept.com/?data=%s&process=true';

Lib/Pkg.Json.Mapper.pas

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,13 @@ function TPkgJsonMapper.GetJsonType(aJsonValue: TJsonValue): TJsonType;
268268
end;
269269

270270
function TPkgJsonMapper.IsValid(aJsonString: string): boolean;
271+
var
272+
Value: TJSONValue;
271273
begin
272-
Result := TJSONObject.ParseJSONValue(aJsonString) <> nil;
274+
Value := TJSONObject.ParseJSONValue(aJsonString);
275+
Result := Value <> nil;
276+
if Result then
277+
Value.Free;
273278
end;
274279

275280
function TPkgJsonMapper.LoadFormFile(aJsonFile: string): TPkgJsonMapper;

0 commit comments

Comments
 (0)