非常简单的程序:
procedure TForm1.Button1Click(Sender: TObject);
var
s: Tform;
begin
if not assigned(s) then //////////////////////////
s:=TForm.Create(application);
s.Show;
end;为何///////////////这一行assigned(s) 总是为true; 我并没有在其他地方创建他的实例。
应该怎样改?
procedure TForm1.Button1Click(Sender: TObject);
var
s: Tform;
begin
if not assigned(s) then //////////////////////////
s:=TForm.Create(application);
s.Show;
end;为何///////////////这一行assigned(s) 总是为true; 我并没有在其他地方创建他的实例。
应该怎样改?
况且我要通过单击主窗体上的按钮来创建一个无模式窗体!!!
你用
s:=nil;////////
if .....
(代理服务器有问题,不能发长的留言,请原谅)
--------------------------------------
看!
那支正飞向太阳的蛾子.....
就是我!
--------------------------------------
(代理服务器有问题,不能发长的留言,请原谅)
--------------------------------------
看!
那支正飞向太阳的蛾子.....
就是我!
--------------------------------------
如果设置优化,编译器将为初始化局部变量,跟踪一下恰好指向FORM1,
所以出现你所讲的问题
如果不设置编译优化,就不会出现该问题。
不过这不是解决问题的根本,
研究中.....
这样编译选项就不会影响你的代码逻辑了。看看DELPHI的帮助已经足够了,如果嫌慢,就来论坛跟大家切磋。
书上说:
与模式窗体不同的是,无法在代码中判断无模式窗体什么时候将删除。因此,无法在创建窗体实例的例程中删除窗体的实例。用户有可能在应用程序正在运行的任何时候关闭无模式窗体。因此,无模式窗体本身一定要把M o d e l e s s 变量设为n i l ,而且最好在处理窗体的O n D e s t r o y 事件的处理过程中设置
这个变量:
procedure TForm1.FormDestroy(Sender: TObject);
begin
s:=nil;
end;可我创建的是动态的无模式窗体,怎样能找到destroy过程?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, ExtCtrls, jpeg;type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure FullFormOnClose(Sender: TObject; var Action: TCloseAction);
public
{ Public declarations }
procedure FullScreen(AControl: TControl);
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
FullScreen(Image1);
end;procedure TForm1.FullFormOnClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree; //当然我这里不是nil一个变量,你把代码写这里
end;procedure TForm1.FullScreen(AControl: TControl);
var
VForm: TForm;
begin
VForm := TForm.Create(Application);
VForm.BorderStyle := bsNone;
VForm.WindowState := wsMaximized;
VForm.OnClose := FullFormOnClose; //在这里设置
AControl.Dock(VForm, VForm.ClientRect);
VForm.Show;
end;end.
Do not call Dock. It is called automatically to implement many of the details of docking the control to a dock site.To dock the control programmatically, use ManualDock instead.但是我使用的时候无法达到图片fullscreen的效果..
AControl.ManualDock(VForm,nil,alClient);???
var
s: Tform;
begin
if not assigned(s) then //////////////////////////
s:=TForm.Create(application);
s.Show;
end;S默认为TForm1, 当然Assigned(S)=True.你可以这样试试procedure NewFrom;
var
s: Tform;
begin
if not assigned(s) then //////////////////////////
s:=TForm.Create(application);
s.Show;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
NewForm;
end;