[lazarus] Dynamic GUI

Shane Miller smiller1 at stvgb.org
Tue May 6 13:47:08 EDT 2003


A.J.

I would do this (or something like this)

  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
    MyButtonList : TList;  //keeps track of the "buttons" created at
runtime
     Procedure ShowEntry(Command, Name, Description, Icon : String);
  end;

  TCommandString = class  //actually creates the button
                          //and handles the onclick.
  private
    fExeCommand: String;
    fButton: TBitBtn;
    FCommand: String;
    FIcon: String;
    FName: String;
    FDescription: String;
    procedure SetCommand(const Value: String);
    procedure SetDescription(const Value: String);
    procedure SetIcon(const Value: String);
    procedure SetName(const Value: String);
    Procedure ButtonClick(Sender : TObject);
  public
    constructor Create(AOwner : TComponent);
    destructor Destroy; override;
    property ExeCommand : String read fExeCommand write fExeCommand;
    property Button : TBitBtn read fButton write fButton;
    property Icon : String read FIcon write SetIcon;
    property Command : String read FCommand write SetCommand;
    property Name : String read FName write SetName;
    property Description : String read FDescription write
SetDescription;
  end;


var
  Form1: TForm1;

implementation

Procedure TForm1.ShowEntry(Command, Name, Description, Icon : String);
Var
  MyNewButton : TCommandString;

Begin
   MyNewButton := TCommandString.Create(self);
   MyNewButton.Icon := Icon;
   MyNewButton.Name := Name;
   MyNewButton.Command := Command;
   MyNewButton.Description := Description;
  //  MyButtonList is a TList that keeps track of the "TCommandString"
objects.
  //  When the form closes, run through the list and free each one.
  MyButtonlist.Add(MyNewButton);
end;



{$R *.dfm}

{ TCommandString }

procedure TCommandString.ButtonClick(Sender: TObject);
begin
  //execute the command here
end;

constructor TCommandString.Create(AOwner : TComponent);
begin
  inherited create;
  fButton := tBitBtn.Create(AOwner);
  fButton.Parent := aOwner;
  fButton.OnClick := ButtonClick;

end;

destructor TCommandString.Destroy;
begin
  fButton.free;
  inherited;
end;

procedure TCommandString.SetCommand(const Value: String);
begin
  FCommand := Value;
end;

procedure TCommandString.SetDescription(const Value: String);
begin
  FDescription := Value;
end;

procedure TCommandString.SetIcon(const Value: String);
begin
  FIcon := Value;
  fButton.Glyph.LoadFromFile(Value);
end;

procedure TCommandString.SetName(const Value: String);
begin
  FName := Value;
end;

End;


...main program....

While mysql_row = mysql_fetch_row(mysql_result) do
	ShowEntry(mysql_row[1],mysql_row[2],mysql_row[3],mysql_row[4]);


End.

Something like that.  Then you would need to place the
"TCommandString.button" at the appropriate place on your form.

Make sense?

Shane


-----Original Message-----
From: A.J. Venter [mailto:ajventer at direqlearn.org] 
Sent: Tuesday, May 06, 2003 9:44 AM
To: lazarus
Subject: RE: [lazarus] Dynamic GUI

I am afraid none of those options would work here.

I want to deliberately prevent the use of hints in this program.
The reason is that it is intended to be part of a system to create a
Linux Application menu for new users. If a user chooses say "Graphics"
from the main menu, a window should come up informing him of the
installed Graphics Programs and explaining what each is, and the
strengths and weaknesses.
For example, Gimp if you want to edit graphics, FLphoto to view large
collections of images etc.

I tend to agree that Tbitbutton would be ideal for the icon and the
name, but can tbitbuttons be loaded from file paths ?
Remember I do not know until runtime what entries will need to be
displayed, and at that time must basically generate the GUI dynamically
based on the database for this category.

Obviously that rules out RAD and the GUI will need to be coded by hand.
Lets asume that a procedure to show each entry is saved in some unit.
The main program would have to do something like this:

While mysql_row = mysql_fetch_row(mysql_result) do
	ShowEntry(mysql_row[1],mysql_row[2],mysql_row[3],mysql_row[4]);


What do you think ?

A.J.
On Tue, 2003-05-06 at 16:35, Shane Miller wrote:
> A.J.
> 
>   One option you could do is create a TBitbtn for each using the Icon
as
> the glyph and the NAME as the text.  Then on a mouseover display the
> Description as a hint.  This would allow you to put many "commands" in
a
> small area because the buttons would be pretty small.
> 
> Otherwise you could use a Listview with the Icon and Text displayed
and
> the Description again being the hint.
> 
> A TTreeView would work too.  Expanding the item would display the
> description.
> 
> If you categorized the commands then you could list them by category
on
> separate tabs which would allow you to break them into smaller parts
and
> make them easier to display.
> 
> Just some thoughts
> Shane
> 
> 
> -----Original Message-----
> From: A.J. Venter [mailto:ajventer at direqlearn.org] 
> Sent: Tuesday, May 06, 2003 8:12 AM
> To: lazarus
> Subject: [lazarus] Dynamic GUI
> 
> Hi,
> A program I am working on, will need to generate most of it's GUI
based
> on a commandline argument.
> With this argument, a search will be done inside an SQL database
> returning records with three fields:
> Command, Name, Description, Icon
> 
> Command, Name and Icon are single line text, the others are multiline
> text.
> 
> What the program then needs to do is to take all the results and
display
> A tabular structure:
> _________________________
> |     |Name		 |
> |Icon |Description       |
> |     |            [Run] |
> -------------------------
> 
> In the above example, Icon must be replaced with an image. The path to
> this image will be the text from the icon field. Name and description
> need merely be displayed.
> 
> [Run] Is a button, which, when executed, will execute command, and
close
> the window.
> If possible, clicking on Icon should perform the same function as
[Run].
> 
> I am curious as to the best way to implement Icon, and the display of
> Name and Description. Keeping in mind that there may well be several
of
> these tables to display, vertically. The implication being that the
> window should resize itself according to the size of the contents, and
> scroll if it can no longer fit them all.
> 
> I have not yet started coding, so I can still change anything (this is
> still pure theory) according to suggestions. 
> 
> I would appreciate any help.
> 
> A.J.
-- 
Story of my life: "Semper in excretum, set alta variant"
A.J. Venter
DireqLearn Linux Guru

_________________________________________________________________
     To unsubscribe: mail lazarus-request at miraclec.com with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


CONFIDENTIALITY NOTICE:
This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information.
Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.






More information about the Lazarus mailing list