[Lazarus] fpGUI

Graeme Geldenhuys graemeg.lists at gmail.com
Sun Jan 16 14:37:54 CET 2011


On Sun, 2011-01-16 at 13:46 +0100, Marco van de Voort wrote:

> If you can't edit it, and must maintain the designer data outside the main
> unit source, I fail to see the advantage of this approach.

Sorry, I don't understand your statement or how it relates to what I
wrote.

Maybe some code example will help reduce confusion with what fpGUI's UI
Designer does.

Lets say the Form unit is called frm_main.pas, it will have a structure
as follows:

----------------[ frm_main.pas ]------------------------
unit frm_main;

interface

uses
  ...

type
  TMainForm = class(TfpgForm)
  private
    {@VFD_HEAD_BEGIN: MainForm}
    Button1: TfpgButton;
    {@VFD_HEAD_END: MainForm}
  public
    procedure AfterCreate;
  end;

implementation

procedure TMainForm.AfterCreate;
begin
  {%region 'Auto-generated GUI code' -fold}
  {@VFD_BODY_BEGIN: MainForm}
  WindowTitle := 'My Test Form';
  SetPosition(10, 10, 400, 300);

  Button1 := TfpgButton.Create(self);
  with Button1 do
  begin
    Name := 'Button1';
    SetPosition(50, 50, 80, 24);
    Text := 'My Button';
    ImageName := 'stdimg.quit';
  end;
  {@VFD_BODY_END: MainForm}
  {%endregion}
end;

end.
--------------------------------------------------------

The fpGUI UI Designer *only* parses and edits the code between the
comment markers. That's those comments that start with {@VFD_xxx}

Only property with non-default values have generated code. Any
user-defined code from the "unknown lines" memo in the Object Inspector
are added to that specific component's source code, just before the
final 'end;' block of code.

AfterCreate is a virtual method that gets called in a base form class in
the AfterConstructor method.

In the case of images, they are handled quite easily as well. fpGUI
allows you to register images per project, but it also includes a set of
default images as standard. Whenever you want to use or set a image, you
simply reference it by its registered name (any text string). So if I
wanted to add the standard 'quit' image to the Button1 above, I simple
set the ImageName property to 'stdimg.quit'

For the above code you will also notice that fpGUI's UI Designer takes
advantage of Lazarus's code folding via the region markers. So by
default all the code managed by the UI Designer is folded (not visible
by the developer, unless they expand it themselves). If you don't want
the code folding, simply delete those lines, the UI Designer will not
add them back in.

You will also notice that the UI components are placed inside the
Private section of the Form class. You can move it to any other pricacy
section if you please. I simply apply standard OOP practises here, just
like what you would do in business objects... Only make visible what you
really want visible. In the case of a Form, I would rather introduce
some public property to extract whatever info it needs from the GUI
components - instead of having the developer go Form.Button1.Tag....
Why? What happens if I remove that button, or rename that button? The
developer would then have to fix there code. Using dedicated properties
instead, reduces this problem.

-- 
Regards,
 - Graeme -

--------------------------------------------------------------
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/





More information about the Lazarus mailing list