Is it possible to dynamically create a form without * .dfm and * .pas files?

Is it possible to create and show TForm without source files? I want to create my forms at runtime and have empty * .dfm and * .pas files, it seems to me useless.

thanks

+6
source share
2 answers

Do you mean this?

procedure TForm1.Button1Click(Sender: TObject); var Form: TForm; Lbl: TLabel; Btn: TButton; begin Form := TForm.Create(nil); try Form.BorderStyle := bsDialog; Form.Caption := 'My Dynamic Form!'; Form.Position := poScreenCenter; Form.ClientWidth := 400; Form.ClientHeight := 200; Lbl := TLabel.Create(Form); Lbl.Parent := Form; Lbl.Caption := 'Hello World!'; Lbl.Top := 10; Lbl.Left := 10; Lbl.Font.Size := 24; Btn := TButton.Create(Form); Btn.Parent := Form; Btn.Caption := 'Close'; Btn.ModalResult := mrClose; Btn.Left := Form.ClientWidth - Btn.Width - 16; Btn.Top := Form.ClientHeight - Btn.Height - 16; Form.ShowModal; finally Form.Free; end; end; 
+10
source

Yes, it is possible:

 procedure TForm1.Button1Click(Sender: TObject); var Form: TForm; begin Form:= TForm.Create(Self); try Form.ShowModal; finally Form.Free; end; end; 
+3
source

Source: https://habr.com/ru/post/904266/


All Articles