thomaserlang / delphi-json

JSON parser for Delphi.
83 stars 32 forks source link

Random AV #24

Closed AdriaanBoshoff closed 4 years ago

AdriaanBoshoff commented 4 years ago

I'm unsure what I'm doing wrong however I seem to be getting a random access violation when trying to read the following file. Using Rad Studio 10.4.1

File:

{
    "Options": {
        "Modded": true,
        "PluginWatchers": true,
        "DefaultGroups": {
            "Players": "default",
            "Administrators": "admin"
        },
        "WebRequestIP": "0.0.0.0"
    },
    "OxideConsole": {
        "Enabled": true,
        "MinimalistMode": true,
        "ShowStatusBar": true
    }
}

Code Reading it: (Gets Executed on Main Form Create event)

procedure TframeuModOxide.ReaduModConfig;
begin  
  if FileExists(OXIDE_CONFIG) then
  begin
    var jdata := TdJSON.Parse(OXIDE_CONFIG);
    try
      // Causes access violation.....
      if jdata['Options']['Modded'].AsBoolean then
        cbbServerListCategory.ItemIndex := 0
      else
        cbbServerListCategory.ItemIndex := 1;

      swtchPluginWatchers.IsChecked := jdata['Options']['PluginWatchers'].AsBoolean;
    finally
      jdata.Free;
    end;
  end;
end;
thomaserlang commented 4 years ago

Are you putting the file path directly into Parse()?

thomaserlang commented 4 years ago

Added ParseFile (https://github.com/thomaserlang/delphi-json/commit/1e165b5efa3c2b936cc22c44237143e20744d930)