Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

Accessing the Interfaces directly

English · Português

This page describes how to write access the underlying widgetset used by lazarus directly (for example: The Windows API, or Gtk, or Qt, etc). One should always try to avoid relying on widgetset specials. This document is here for both people improving the widgetsets and for people writing components that really need to access the widgets directly.

Overview

Every TWinControl has a handle, and the LCL does not need to know, what a Handle is. The meaning of the Handle is totally up to the interface:

Per-Widgetset Details

Qt

Handles on Qt are mostly pointers to objects. Every time a control is created, a helper object is also created and both are connected. The helper object is necessary to receive events from Qt. After receiving an event it will send it to the LCL.

Most of those objects are descendents from TQtWidget as declared below:

pascal
{ TQtWidget }

TQtWidget = class(TObject)
private
  ...
public
  Widget: QWidgetH;
  LCLObject: TWinControl;
public
  function  GetContainerWidget: QWidgetH; virtual;
  ...
end;

Notice the two variables they all contain:

And also this method:

Carbon

Handles on Carbon are very similar to Qt ones. The helper classes are descended from abstract class TCarbonWidget.

pascal
{ TCarbonWidget }

TCarbonWidget = class(TObject)
private
public
  Widget: Pointer;
  LCLObject: TWinControl;
end;

Notice the two variables they all contain:

Windows

Handles on Win32 or WinCE are almost always the same as their corresponding Win api handles. For example the handle for a TMenu is an HMENU, the handle for a TBrush is an HBRUSH. You simply pass one such handle as a parameter in a Windows api call.

List of Handles on various LCL classes

TFont

TCanvas

TBrush

TBitmap

You can access this on Gtk using:

pascal
var
  GDIObject: PGDIObject;
  Bitmap: TBitmap;
  AImage: PGtkWidget;
begin
  ...

  GDIObject := PgdiObject(Bitmap.Handle);

  AImage := gtk_image_new_from_pixmap(GDIObject^.GDIPixmapObject,
   GDIObject^.GDIBitmapMaskObject);

  gtk_widget_show(AImage);

  gtk_container_add(GTK_CONTAINER(MyForm.Handle), AImage);
end;

TCustomForm

TMenu, TMainMenu, TMenuItem and TPopUpMenu

See also


From the Free Pascal wiki, page "Accessing the Interfaces directly", as it stood on 2020-03-09 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 3, last changed by WikiArchive .