我今天看到一个简单的程序,就是有三个窗口,FORM2作为主窗口,其余两个作为可引用的窗口,在FORM2表单中有 use unit3,但没有use unit1,可以在程序中照样引用了form1的窗口变量,这不知为什么,我试着去掉了use unit3,结果引用FORM3变量的语句报错,但为什么引用 form1的窗口变量的语句就不会报错呢?
解决方案 »
- Delphi使用MyDAC连接MySQL数据库报错?
- 请问 如何在 模式窗体 show 出来的窗体 总在 模式窗体 最前面???????????
- 一个超难的查询问题,Access数据库SQL语言相关
- dll加载失败,通常是什么原因导致的???
- 这堆冒号点的有问题,给看看哪点多了!!!!!!!!!!!!!!!!!
- 关于DLL的问题,超容易一时想不开又没时间去搜请大家帮忙.
- delphi二维动态数组赋值出现问题,请各位指点!!
- 关于MSSQL数据删除问题?
- delphi 如何实现程序的自动重启
- 内存数据怎么copy
- 如何实现在打印预览的时候也可以像DBGrid一样可以调整单元格的大小?请高手帮忙!
- 如何反白显示当前记录
unit1的引用方法?
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, Unit3;type
TForm2 = class(TForm)
BitBtn1: TBitBtn;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
BitBtn2: TBitBtn;
Label4: TLabel;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
procedure Button1Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;
AboutBox: TAboutBox;implementationuses Unit1;{$R *.DFM}procedure TForm2.Button1Click(Sender: TObject);
begin
MessageDlg('This button just gives you something to look at when the application starts.', mtInformation,
[mbOk], 0);end;procedure TForm2.BitBtn1Click(Sender: TObject);
begin
close;
end;procedure TForm2.BitBtn2Click(Sender: TObject);
begin
AboutBox := TAboutBox.Create(Application);
AboutBox.ShowModal;
end;procedure TForm2.BitBtn3Click(Sender: TObject);
begin
Form_Splash := TForm_Splash.Create(Application); {Builds the actual Splash Form}
Form_Splash.Show;
Form2.Show;
end;procedure TForm2.BitBtn4Click(Sender: TObject);
begin
Form_Splash.Close;
end;end.这是unit3的代码:
unit Unit3;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 TAboutBox.OKButtonClick(Sender: TObject);
begin
close;
end;end.这是unit1的代码:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;type
TForm_Splash = class(TForm)
Image1: TImage;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form_Splash: TForm_Splash;implementation{$R *.DFM}procedure TForm_Splash.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree; {further ensures the resources for your Splash Form are freed}
end;end.下面是项目文件:
program Project1;uses
Forms,
Unit1 in 'Unit1.pas' {Form_Splash},
Unit2 in 'Unit2.pas' {Form2},
Unit3 in 'Unit3.pas' {AboutBox};{$R *.RES}begin
Application.Initialize;
Form_Splash := TForm_Splash.Create(Application); {Builds the actual Splash Form}
Form_Splash.Show; {Sets the Splash screen to show, but since the application
is still initializing, it won't actually show until . . .}
Form_Splash.Refresh; {Until you do this command!}
Application.CreateForm(TForm2, Form2);
Form_Splash.Hide; {Hides the Splash Form, allows your Main Form to be displayed}
Form_Splash.Free; {Releases the resources used by your Splash Form! Important!!}
Application.Run;
end.