About对话框文件:
unit about;interfaceuses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls;type
TAboutBox = class(TForm)
Panel1: TPanel;
ProgramIcon: TImage;
ProductName: TLabel;
Version: TLabel;
Copyright: TLabel;
Comments: TLabel;
OKButton: TButton;
procedure OKButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
AboutBox: TAboutBox;implementation{$R *.dfm}procedure ShowAboutBox;
begin
with TAboutBox.Create(Application)do
try
ShowModal;
finally
Free;
end;
end;procedure TAboutBox.OKButtonClick(Sender: TObject);
begin
AboutBox.Destroy;
end;
end.
调用文件:
unit main;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ToolWin, ComCtrls, ImgList;type
TMainForm = class(TForm)
................
MainMenu1: TMainMenu;
procedure N15Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure N11Click(Sender: TObject);
procedure ToolButton13Click(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
procedure ShowAbout;
end;var
MainForm: TMainForm;
implementation
uses
fenlei,about;
{$R *.dfm}procedure TMainForm.ShowAbout;begin
ShowAboutBox;//调用unit about 文件中的函数//但是在这里程序出错.
end;procedure TMainForm.N11Click(Sender: TObject);
begin
ShowAbout;
end;procedure TMainForm.ToolButton13Click(Sender: TObject);
begin
ShowAbout;
end;end.为什么这样不行啊~
unit about;interfaceuses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls;type
TAboutBox = class(TForm)
Panel1: TPanel;
ProgramIcon: TImage;
ProductName: TLabel;
Version: TLabel;
Copyright: TLabel;
Comments: TLabel;
OKButton: TButton;
procedure OKButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
AboutBox: TAboutBox;implementation{$R *.dfm}procedure ShowAboutBox;
begin
with TAboutBox.Create(Application)do
try
ShowModal;
finally
Free;
end;
end;procedure TAboutBox.OKButtonClick(Sender: TObject);
begin
AboutBox.Destroy;
end;
end.
调用文件:
unit main;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ToolWin, ComCtrls, ImgList;type
TMainForm = class(TForm)
................
MainMenu1: TMainMenu;
procedure N15Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure N11Click(Sender: TObject);
procedure ToolButton13Click(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
procedure ShowAbout;
end;var
MainForm: TMainForm;
implementation
uses
fenlei,about;
{$R *.dfm}procedure TMainForm.ShowAbout;begin
ShowAboutBox;//调用unit about 文件中的函数//但是在这里程序出错.
end;procedure TMainForm.N11Click(Sender: TObject);
begin
ShowAbout;
end;procedure TMainForm.ToolButton13Click(Sender: TObject);
begin
ShowAbout;
end;end.为什么这样不行啊~
ShowAboutBox;//调用unit about 文件中的函数//但是在这里程序出错.
end;--->procedure TMainForm.ShowAbout;
var F:TAboutBox;
begin
try
F:=TAboutBox.Create(Application);
F.ShowAboutBox;
finally
F.Free;
end;
end;//------------------------------
这样试试,如果不行,那就直接使用默认的创建方式(不是现在的动态创建),
//------------------------------
unit about;interface.......type
TAboutBox = class(TForm)
......
end;var
AboutBox: TAboutBox;implementation{$R *.dfm}procedure ShowAboutBox;//在main中要被调用de
begin
with TAboutBox.Create(Application)do
try
ShowModal;
finally
Free;
end;
end;...
end.
调用文件:
unit main;interface.....
type
TMainForm = class(TForm)
.......
private
{ Private declarations }
public
{ Public declarations }
procedure ShowAbout;
end;var
MainForm: TMainForm;implementation
uses
about;
{$R *.dfm}procedure TMainForm.ShowAbout;begin
ShowAboutBox;//调用unit about 文件中的函数//但是在这里程序出错.
end;procedure TMainForm.N11Click(Sender: TObject);
begin
ShowAbout;
end;end.为什么这样不行啊~
如果是动态的请先创建!