Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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