delphi10 创建窗体代码
时间: 2024-05-25 19:13:49 浏览: 10
在 Delphi 10 中,创建窗体的代码通常是通过使用 TForm 类来实现的。下面是一个简单的示例,演示如何在 Delphi 10 中创建一个新的窗体:
1. 在 Delphi 10 中,选择 File -> New -> VCL Forms Application 以创建一个新的应用程序。
2. 在主窗体的代码中声明一个新的 TForm 对象,例如:
var
Form2: TForm;
3. 在需要创建新窗体的地方,使用 New 关键字创建一个新的 TForm 实例,例如:
Form2 := TForm.Create(nil);
4. 设置新窗体的属性,例如:
Form2.Caption := 'New Form';
Form2.Width := 400;
Form2.Height := 300;
5. 显示新窗体,例如:
Form2.Show;
完整的代码示例:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
Form2: TForm;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
// Create new form
Form2 := TForm.Create(nil);
// Set form properties
Form2.Caption := 'New Form';
Form2.Width := 400;
Form2.Height := 300;
// Show form
Form2.Show;
end;
end.