How to create a TForm dynamically lazarus / 31-LCL ---------------------------------------------------------------------- rc.1990 · 2016-09-23 17:32 Is it possible to create a TForm dynamically without having the files .pas and .lfm? If possible, I am trying to do something similar to inputbox or showmessage or messagedlg, but including a TPanel and a TImage and some more Labels and Edits. ---------------------------------------------------------------------- djzepi · 2016-09-23 18:02 See wiki: http://wiki.lazarus.freepascal.org/Form_Tutorial#Generate%20the%20form %20dynamically ---------------------------------------------------------------------- rc.1990 · 2016-09-23 18:16 Thanks. ---------------------------------------------------------------------- wp · 2016-09-23 18:42 Although djzepi was faster, here's an advanced example in which a dialog with a radiogroup is created dynamically; the example makes heavy use of the autosizing properties available in Lazarus: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function RadioButtonDialog(ACaption, Alabel: String; const AItems: array of string;  var AItemIndex: Integer): Boolean;var  F: TForm;  rg: TRadioGroup;  i: Integer;  cancelBtn, okBtn: TButton;  w, h: Integer;begin  F := TForm.Create(nil);  try    F.Caption := ACaption;     // Create the radiogroup    rg := TRadioGroup.Create(F);    rg.Parent := F;    // Set caption of radiogroup    rg.Caption := ALabel;    // Create items of radiogroup  for i:=0 to High(AItems) do      rg.Items.Add(AItems[i]);    // Select the predefined item    rg.ItemIndex := AItemIndex;    // Automatically determine size of radiogroup    rg.BorderSpacing.Around := 8;    rg.AutoSize := true;    rg.HandleNeeded;    rg.GetPreferredSize(w, h);    rg.AutoSize := false;    rg.Align := alTop;    rg.Height := h;     // Create the OK button    okBtn := TButton.Create(F);    okBtn.Parent := F;    okBtn.Caption := 'OK';    okBtn.ModalResult := mrOK;    okBtn.Default := true;     // Create the Cancel button    cancelBtn := TButton.Create(F);    cancelBtn.parent := F;    cancelBtn.BorderSpacing.Around := 8;    cancelBtn.Caption := 'Cancel';    cancelBtn.Cancel := true;    cancelBtn.ModalResult := mrCancel;     // Automatically position the cancel button underneath the radiogroup and    // anchor it to the right of the form    cancelBtn.AnchorSideTop.Control := rg;    cancelBtn.AnchorSideTop.Side := asrBottom;    cancelBtn.Anchors := [akTop, akRight];    cancelBtn.AnchorSideRight.Control := F;    cancelBtn.AnchorSideRight.Side := asrBottom;     // Automatically position the OK button to the left of the cancel button    okBtn.BorderSpacing.Around := 8;    okbtn.AnchorSideTop.Control := rg;    okbtn.AnchorSideTop.Side := asrBottom;    okbtn.Anchors := [akTop, akRight];    okbtn.AnchorSideRight.Control := cancelbtn;    okbtn.AnchorSideRight.Side := asrLeft;     // Automatically determine best size of the form    F.AutoSize := true;     // Position the form in the screen center    F.Position := poScreenCenter;     // Show form modally    if F.ShowModal = mrOK then begin      Result := true;      AItemIndex := rg.ItemIndex;    end else      Result := false;  finally    F.Free;  end;end; procedure TForm1.Button1Click(Sender: TObject);var  sel: Integer;begin  sel := 0;  if RadioButtonDialog(    'Please select',    'Options',    ['1st item', '2nd item', '3rd item', '4th item - very, very, very long text',     '5th item', '6th item', '7th item'],     sel)  then    ShowMessage('Item ' + IntToStr(sel) + ' selected');end; ---------------------------------------------------------------------- howardpc · 2016-09-23 19:15 And attached is a similar sort of example that includes a panel, image, label and edit. ---------------------------------------------------------------------- rc.1990 · 2016-09-23 22:01 Thanks, wp and howardpc.