[Lazarus] Creating SDK like system

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Wed Apr 13 17:26:29 CEST 2011


It depends on a lot on the kind of level that you want to expose in
your API. Also will the API be accessed from Pascal or C?

One design goes like this:

Main Program --> Plugin DLL

In the DLL make one routine which will receive a structure filled with
pointers to APIs exported by the main program. Then the plugin DLL can
use those APIs.

One example of API that the main program can expose:

function AddTEditToMainForm(APos: TPoint; ASize: TSize; ACaption: PChar): TEdit;
begin
  Result := TEdit.Create(MyForm);
  Result.Parent := MyForm;
  Result.Width := ASize.Width; // or similar, don't remember what comes in TSize
  // do the same for the other coordinates and other stuff too
end;

In C TEdit can be treated as an opaque pointer.

Similarly from Pascal when importing this function one option is
threading the TEdit as an opaque pointer to avoid the problem of
getting an unified memory and a unified RTL.

The plugin system in the Virtual Magnifying Glass works like that:
http://sourceforge.net/projects/magnifier/

-- 
Felipe Monteiro de Carvalho




More information about the Lazarus mailing list