Skip to content
GitLab
    • GitLab: the DevOps platform
    • Explore GitLab
    • Install GitLab
    • How GitLab compares
    • Get started
    • GitLab docs
    • GitLab Learn
  • Pricing
  • Talk to an expert
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
    Projects Groups Snippets
  • Sign up now
  • Login
  • Sign in / Register
  • FPC Source FPC Source
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 1,357
    • Issues 1,357
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 71
    • Merge requests 71
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • FPC
  • FPCFPC
  • FPC SourceFPC Source
  • Issues
  • #22273
Closed
Open
Issue created Jun 15, 2012 by FPC Admin account@fpc_adminOwner

Control whether TJSONObject.GetElements raises Exception when element not found

Original Reporter info from Mantis: dezlov
  • Reporter name: Denis Kozlov

Description:

In the latest mainstream version FPC 2.6.0 the JSON functionality has been modified in such a way that breaks existing applications.

TJSONObject.GetElements method is used for retrieving TJSONData by name. Prior to FPC 2.6.0, if the element was not found by the specified name the method would return NIL. In FPC 2.6.0, however, the method raises an Exception when this occurs.

Can I suggest adding an option (property) which will control this new behavior and will allow developers to switch off these exceptions. I understand that we can use IndexOfName method prior to getting the element, but this will require modification of very line of code where JSON elements are being used.

FPC 2.4.2:

----------------------------------------
function TJSONObject.GetElements(AName: string): TJSONData;
begin
  Result:=TJSONData(FHash.Find(AName));
end;
----------------------------------------

FPC 2.6.0:
----------------------------------------
function TJSONObject.GetElements(Const AName: string): TJSONData;
begin
  Result:=TJSONData(FHash.Find(AName));
  If (Result=Nil) then
    Raise EJSON.CreateFmt(SErrNonexistentElement,[AName]);
end;
----------------------------------------

Previously working code breaks in 2.6.0:
----------------------------------------
var
  J: TJSONObject;
  D: TJSONData;
begin
  J := TJSONObject.Create;
  D := J['dummy'];
  if D = nil then
    Write('Dummy does not exist...');
  else
    Write('Found the dummy...');
----------------------------------------

Mantis conversion info:

  • Mantis ID: 22273
  • Version: 2.6.0
  • Monitored by: » dezlov (Denis Kozlov)
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking