Class TDynLib
Unit
Declaration
type TDynLib = class(TObject)
Description
Load functions from dynamic libraries.
This class allows to load functions from dynamic libraries (.dll on Windows, .so on most Unix platforms, .dylib on macOS and iOS).
Features:
The Load and Symbol functions by default do error checking (and raise necessary exceptions).
The field SymbolError allows to specify once for all subsequent Symbol calls what error checking we want. Default is to check errors and raise exceptions. There is also a very usefull value reWarnAndContinue: it allows you to run program once and see all symbols that are missing from dynamic library.
The interface of this is OS-independent and works for both FPC and Delphi.
Typical usage:
var ALLibrary: TDynLib = nil; initialization ALLibrary := TDynLib.Load('libopenal.so.1'); { ... some calls to ALLibrary.Symbol() ... } finalization FreeAndNil(ALLibrary); end.
It is important that ALLibrary is initialized to nil and that in finalization you use FreeAndNil. This allows you to exit gracefully if library does not exist on the system and Load will raise an exception: ALLibrary will stay then as nil.
Hierarchy
- TObject
- TDynLib
Overview
Methods
constructor Create(const AName: string; AHandle: TDynLibHandle); |
|
destructor Destroy; override; |
|
class function Load(const AName: string; RaiseExceptionOnError: boolean = true): TDynLib; |
|
function Symbol(const SymbolName: PChar): Pointer; |
Properties
property Name: string read FName; |
|
property SymbolError: TDynLibSymbolError
read FSymbolError write FSymbolError default seRaise; |
|
property SymbolErrorBehaviour: TDynLibSymbolError
read FSymbolError write FSymbolError default seRaise; deprecated 'use SymbolError'; |
Description
Methods
constructor Create(const AName: string; AHandle: TDynLibHandle); |
|
Standard constructor, requires a valid TDynLibHandle already. Usually you will prefer to use Load method instead of directly calling this constructor. Exceptions raised
|
destructor Destroy; override; |
|
class function Load(const AName: string; RaiseExceptionOnError: boolean = true): TDynLib; |
|
Link to a dynamic library specified by Name. Returns created TDynLib instance. If the library is not found and RaiseExceptionOnError is Note that the default situation prevents from unintentionally ignoring an error and that's good. Exceptions raised
|
function Symbol(const SymbolName: PChar): Pointer; |
|
Return address of given symbol (function name etc.) from loaded dynamic library. If the symbol doesn't exist, then SymbolError says what happens:
Exceptions raised
|
Properties
property SymbolError: TDynLibSymbolError
read FSymbolError write FSymbolError default seRaise; |
|
What happens when Symbol fails. |
property SymbolErrorBehaviour: TDynLibSymbolError
read FSymbolError write FSymbolError default seRaise; deprecated 'use SymbolError'; |
|
Warning: this symbol is deprecated: use SymbolError |
Generated by PasDoc 0.16.0.