[Lazarus] OSX: Handles and WindowRefs

Marc Weustink marc at dommelstein.net
Sun Jan 11 17:57:18 CET 2009


Duncan Parsons wrote:
> Hi,
> 
> I seem to have run into a problem with what is essentially
> nomenclature..
> 
> Since LCL has used Delphi as its template, there's a lot of Windows
> based conventions, but that doesn't totally map to other systems.

Indeed, that is why a Reference property as Handle replacement is 
introduced.

> For instance, TForm.Handle in windows repesents the tag that the OS
> gives to the rectangle I see on screen. I would have thought that each
> underlying widgetset interface would then use this to maintain some
> consistency at a higher level, eg on OSX, this would be filled with the
> WindowRef that OSX uses. However, I cannot see this happening (unless
> I'm looking in the wrong place). TCarbonWindow has a fWindowRef field
> and property that references it, but this is at widgetset level, and so
> not visible to TForm.

Each Widgetset is free to return whatever it likes ad Handle to their 
underlying data structures.
As you can see in other replies, for carbon it was
   AWindow  := WindowRef(TCarbonWidget(Form1.Handle).Widget);
and now
   AWindow  := TCarbonWindow(Form1.Handle).Window;

The idea behind TWInControl.Reference is to abstract this and to allow 
direct widgetaccess the same time. In the future retrieving the window 
would become something like:
   AWindow := WinControl.Reference as ICarbonHiView).Window;

or similar for gtk
   AWindow := WinControl.Reference as IGdkWindow).Window;

etc..

Ofcoarse this is all future and depends a bit on when I feel like doing 
such big change.

> I see the HandleAllocated and GetReferenceAllocated code lying around,

THats indeed the start.

> but they don't seem to tell me what I'm after. What I'd like to know is
> if I have a function in OSX that is asking for a form's WindowRef, do I
> pass it self.Handle, or is there something else I should be using. At
> the moment it is not working as I would hope. For instance calling
> GetWindowAttributes(WindowRef(self.Handle),myAttributes) gives me an
> exception each time.
> 
> Any ideas on what I should be looking for?

See other replies.

Marc




More information about the Lazarus mailing list