我的项目中有2个Form(Form1和Form2),Form1是自动创建表单,但Form2是可用表单.我怎么能创建Form2并卸载Form1?
我在此代码中收到"访问验证"错误.
这是Form1代码:
1. uses Unit2;
//*********
2. procedure TForm1.FormCreate(Sender: TObject);
3. var a:TForm2;
4. begin
5. a := TForm2.Create(self);
6. a.Show;
7. self.free; // Or self.destory;
8. end;
Run Code Online (Sandbox Code Playgroud)
谢谢.
我将"Serg"代码修改为:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.CreateForm(TForm2, Form2);
Release; …Run Code Online (Sandbox Code Playgroud)