Author Topic: interface builder?  (Read 12456 times)


  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2515
interface builder?
« Reply #15 on: March 26, 2008, 10:19:29 am »
Thanks! I'm flattered! =)

1. There's not way to setup event handling visually with IB. Just beacuse IB knows nothing about the programming language it's going to be used by.
2. I think it's quite possible to use IB created pages with Lazarus applications. IB routines simply creates MacOS windows and controls and lays them out as designed. The required thing is to assign control handles to the widgetset objects, so IB created controls can be used easily.

Here's the sample =)
Start new lazarus application. Place a single button on the form. And build and Run, Lazaurs should create an application bundle.
Close the application, and open it's bundle. You need to copy main.nib file from the bundle of the previous tutorial, to the Lazarus application bundle. Don't forget that bundle must be located in the Bundle/Contents/Resources folder.

Now return to the Lazarus and open Form unit. Assign OnClick event handler for the button.

Paste following code to it.
Code: [Select]

procedure TForm1.Button1Click(Sender: TObject);
  err     : Integer;
  nibRef  : IBNibRef;
  winref  : WindowRef;
  NibForm : TForm;
  err := CreateNibReference(CFSTR('main'), nibRef);
  if err <> noErr then  Exit;
    err := CreateWindowFromNib(nibRef, CFSTR('Window'), winref);
    if err <> noErr then Exit;

    // creating a widgetset object (TForm)
    NibForm := TForm.Create(Application);

    //HACK: this code is not cross-platform, and will work for Carbon only!
    //binding widgetset object and MacOS system object winref: WindowRef
    TCarbonWindow(NibForm.Handle).Widget := winref;
    // Now Nib created window can be manipulated by the LCL object
    NibForm.Caption := 'Hello LCL!';

add: FPCMacOSALL and CarbonPrivate untis to the uses
That's it! Pressing the button should open IB created window!
threre're two problems with this method
1) it's not cross-platfrom
2) it requires you STRONG knowledge of LCL and carbon widgetst internals!

The solution is the similiar to the one in Windows, then you want to create new Win controls by calling winAPI functions and use them with LCL (delphi VCL) code.
Patron Cocoa Widgetset development


  • Jr. Member
  • **
  • Posts: 63
interface builder?
« Reply #16 on: March 27, 2008, 09:19:04 am »
Great! Thanks.


TinyPortal © 2005-2018