[Lazarus] Sample code needed to create form at runtime only (see mock up below).

Peter E Williams foss.game.pascal.developer at iinet.net.au
Sun Sep 5 11:18:49 CEST 2010


Hi Felipe and All,

On Sun, 2010-09-05 at 07:01 +0200, Felipe Monteiro de Carvalho wrote:
> On Sun, Sep 5, 2010 at 6:39 AM, Peter E Williams
> <foss.game.pascal.developer at iinet.net.au> wrote:
> > Questions:
> > 1) Does the Memo1, OK_Button and Cancel TButton need to be in a
> > TGroupBox???
> > 2) Also, should the TImage be in a TGroupBox???
> 
> I think that to use the splitter you need to group the elements using
> a panel. I vaguely remember that if you have something like:
> 
> Panel 1 - Splitter - Panel 2

My question is:
How do I create a TForm and TSplitter and 2 x TPanel's at runtime?!?

I would guess something like:
{ this code is all untested and typed straight into my email client }

procedure create_formA( 
  Image_filename : string; StringList1 : TStringList );
var
  FormA : TForm;
  Splitter1 : TSplitter;
  Panel1, Panel2 : TPanel;
  success_modal_result : boolean;
  OK_button, Cancel_button : TButton;
  Image1 : TImage;
begin
  FormA := TForm.Create; // Are there any parameters here????

  try
    FormA.caption := 'Image and Comments for ' + Image_filename;

    Splitter1 := TSplitter.Create( FormA );
    Splitter1.Parent := FormA;
    Splitter1.Visible := True;
    Splitter1.Align := alRight;
    // do I need to set any other properties like Height, Width, Top,
Left ???

    Panel1 := TPanel.Create( FormA );
    Panel1.Parent := FormA;
    Panel1.Visible := True;
    Panel1.Align := alClient;

    Memo1 := TMemo.Create( FormA );
    Memo1.Parent := Panel1;
    Memo1.Visible := True; 

    Memo1.Align := ?????????
    // do I need to set any other properties like Height, Width, Top,
Left ???

    // will this work ????

    Memo1.Strings := StringList1.Strings;

    OK_Button := TButton.Create( FormA );
    OK_Button.Parent := FormA;
    OK_Button.Visible := True;
    OK_Button.ModalResult := mrOK;

    OK_Button.Align := ????????????
    // do I need to set any other properties like Height, Width, Top,
Left ???

    Cancel_Button := TButton.Create( FormA );
    Cancel_Button.Parent := FormA;
    Cancel_Button.Visible := True;
    Cancel_Button.ModalResult := mrCancel;

    Cancel_Button.Align := ??????????
    // do I need to set any other properties like Height, Width, Top,
Left ???

    Panel2 := TPanel.Create( FormA );
    Panel2.Parent := FormA;
    Panel2.Visible := True;
    Panel2.Align := alRight;

    Image1 := TImage.Create( FormA );
    Image1.Parent := Panel2;
    Image1.Visible := True;

    Image1.Align := ??????????
    // do I need to set any other properties like Height, Width, Top,
Left ???

    // will this work ????

    if FileExists ( Image_filename ) then
    begin
      Image1.Filename := Image_filename;
      Image1.LoadFromFile( Image_filename );
    end
    else
      showmessage( 'Error: Image filename "+ Image_filename + '" Cannot
be loaded because it does not exist.'); 

    // Showmodal the form!!!
    success_modal_result := (formA.showmodal = mrOK);
  finally
    FormA.free; // free the form
    // all the other components will automatically be freed because 
    // they were created with FormA as their create parameter.
  end;
end;

I would appreciate it if anyone could be fill in the Align statement
question marks and comment on the code below the comments "will this
work ????".

> Then Panel 1 should have Align=alClient, Splitter.Align = alRight,
> Panel2.Align = alRight
> 
> Yes, a group box would probably do it as well, but the panel is just
> as good and can be configured to have no borders and the user won't
> note he is in the form.

Best Regards,
	PEW
Hobart, Tasmania, Australia

-- 
Proudly developing Quality Cross Platform Open Source Games
Since 1970 with a Commodore PET 4016 with 16 KRAM
http://pews-freeware-games.org (<--- brand new)





More information about the Lazarus mailing list