Sign in Join
Wiki copytemporary

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 .

Edited on wiki.freepascal.org by 11 people, 2006–2020

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
Mattias2
Mattias2
Sekelsenmat
Sekelsenmat
Sekelsenmat (minor)
SekelsenmatTBitmap
SekelsenmatTBitmap
SekelsenmatTBitmap (minor)
Sekelsenmat (minor)
Sekelsenmat
SekelsenmatQt (minor)
SekelsenmatTCustomForm
SekelsenmatList of Handles on various LCL classes
SekelsenmatList of Handles on various LCL classes
Roozbeh
Roozbeh
Swen (minor)
SekelsenmatTBitmap
Sekelsenmat
Swen (minor)
TomboList of Handles on various LCL classes
TomboList of Handles on various LCL classes
Tombo
Tombo (minor)
SekelsenmatTCustomForm
SekelsenmatTCanvas
SekelsenmatTCanvas
Sekelsenmat
SekelsenmatOverview
TomboTMenu, TMainMenu, TMenuItem and TPopUpMenu
SekelsenmatTCanvas
SekelsenmatTCanvas
SekelsenmatQt
SekelsenmatTCustomForm
Chronos
VincentText replace - "delphi>" to "syntaxhighlight>" (minor)
Jwdietrich
JwdietrichLink had to be reconstructed after Swen deleted the redirect page...
Jwdietrichcategorization
JwdietrichCapitalization
Jwdietrichcapitalization (minor)
Jwdietrichcapitalization
JwdietrichLinks added.
JwdietrichLinks added.
HowardPCWindows (minor)
HowardPCWindows (minor)
TrevFixed syntax highlighting (minor)
BartPer-Widgetset Details: typo (minor)
TrevAdded See also section; moved categories to page template (minor)
TrevSee also: Updated (minor)

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.