DynaPDF Manual - Page 46

Previous Page 45   Index   Next Page 47

Language Bindings
Page 46 of 839
returned. All internal used resources will be freed, there is no need to call FreePDF() manually
beforehand.
Example (Single threaded):
In the following example we use a simple message box inside the error callback function.
However, in a larger project it makes sense to output error messages into an error log or list
box. DynaPDF ignores non-fatal errors by default so that it is possible to continue, but you can
protocol each warning and errors during PDF creation.
unit Unit1;
interface
uses Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs,
StdCtrls, dynapdf; // Include the file dynapdf.pas to the unit
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var Form1: TForm1;
implementation
// First, we define our callback function that is called if an
// error occurred. Note: The calling convention is stdcall!
function ErrProc(const Data: Pointer; ErrCode: Integer; const
ErrMessage: PAnsiChar; ErrType: Integer): Integer; stdcall;
var s: String;
begin
s := Format('%s'#13'Abort processing?', [ErrMessage]);
if MessageDlg(s, mtError, [mbYes, mbNo], 0) = mrYes then
Result := -1 // break processing
else
Result := 0; // try to continue
end;
procedure TForm1.Button1Click(Sender: TObject);
var pdf: TPDF;
begin
pdf := nil;
try
pdf := TPDF.Create;
// set the error callback function first
pdf.SetOnErrorProc(nil, @ErrProc);
pdf.SetDocInfoA(diAuthor, 'Jens Boschulte');
pdf.SetDocInfoA(diCreator, 'Delphi sample project');
pdf.SetDocInfoA(diSubject, 'My first PDF file...');
 

Previous topic: Exception handling in Delphi, Using DynaPDF in Multithreading Applications

Next topic: Compiling DynaPDF on Linux / UNIX, System requirements:, Build process