Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get JSON Details from the Last PFX Operation
See more PFX/P12 Examples
Demonstrates Pfx.GetLastJsonData, which replaces the contents of a JsonObject with structured JSON information from the most recent operation.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Tip: Code to parse the returned JSON can be generated with Chilkat's online tool at https://tools.chilkat.io/jsonParse.
Background. The data is copied as a complete replacement and is never merged with existing members. The exact members depend on the operation that produced them.
Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Pfx,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
pfx: TPfx;
password: string;
json: TJsonObject;
jsonStr: string;
begin
success := False;
pfx := TPfx.Create;
// The file path is relative to the application's current working directory. An absolute path
// may also be used. Supply the path appropriate to your own environment.
// The PFX password should come from a secure source rather than being hard-coded.
password := 'myPfxPassword';
success := pfx.LoadPfxFile('qa_data/identity.pfx',password);
if (success = False) then
begin
WriteLn(pfx.LastErrorText);
Exit;
end;
// Copy structured JSON information from the most recent operation into a JsonObject. The contents
// entirely replace anything already in the object.
json := TJsonObject.Create;
pfx.GetLastJsonData(json);
json.EmitCompact := False;
jsonStr := json.Emit();
WriteLn(jsonStr);
// JSON parsing code for this result can be generated at Chilkat's online tool:
// https://tools.chilkat.io/jsonParse
pfx.Free;
json.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.