Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get JSON Details from the Last Operation
See more MIME Examples
Demonstrates GetLastJsonData, which copies structured details from the most recent operation into a JsonObject when such details are available. Many operations produce no JSON data, in which case the object is empty or minimal.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths 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. Some Chilkat operations expose extra diagnostic or result information as JSON. GetLastJsonData provides access to that information after the operation completes.
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.Mime,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mime: TMime;
pfxPassword: string;
json: TJsonObject;
jsonStr: string;
begin
success := False;
mime := TMime.Create;
success := mime.LoadMimeFile('qa_data/encrypted.eml');
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
// Some operations produce structured JSON details. After an operation, copy those details into a
// JsonObject with GetLastJsonData. Many methods produce no JSON, in which case the object is
// little or empty.
pfxPassword := 'myPfxPassword';
success := mime.AddPfxSourceFile('qa_data/recipient.pfx',pfxPassword);
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
success := mime.Decrypt();
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
json := TJsonObject.Create;
mime.GetLastJsonData(json);
json.EmitCompact := False;
jsonStr := json.Emit();
WriteLn(jsonStr);
mime.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.