非常简单的程序:
procedure TForm1.Button1Click(Sender: TObject);
var
  s: Tform;
begin
  if not assigned(s) then  //////////////////////////
    s:=TForm.Create(application);
  s.Show;
end;为何///////////////这一行assigned(s) 总是为true; 我并没有在其他地方创建他的实例。
应该怎样改?

解决方案 »

  1.   

    可能是你在工程文件里已经创建了,把在工程文件中的Create去掉再试下!
      

  2.   

    把在工程文件中的Create去掉没法创建主窗体呀,
    况且我要通过单击主窗体上的按钮来创建一个无模式窗体!!!
      

  3.   

    s为局部变量,在进入函数体的时候分配了空间,但没有初始化;
    你用
    s:=nil;////////
    if .....
    (代理服务器有问题,不能发长的留言,请原谅) 
    --------------------------------------
    看!
    那支正飞向太阳的蛾子.....
    就是我!
    --------------------------------------
      

  4.   

    assigned是用来看是否为空,没有初始化并不等于就是为空!Assigned can't detect a dangling pointer--that is, one that isn't nil but no longer points to valid data. For example, in the code example for Assigned, Assigned won't detect the fact that P isn't valid.
    (代理服务器有问题,不能发长的留言,请原谅) 
    --------------------------------------
    看!
    那支正飞向太阳的蛾子.....
    就是我!
    --------------------------------------
      

  5.   

    firetoucher(风焱) 讲的有道理,不过这种情况跟编译配置选项也有关。
    如果设置优化,编译器将为初始化局部变量,跟踪一下恰好指向FORM1,
    所以出现你所讲的问题
    如果不设置编译优化,就不会出现该问题。
      

  6.   

    project->option->Compiler->Code Generation->Optimization
    不过这不是解决问题的根本,
    研究中.....
      

  7.   

    把s(: Tform;)设为全局的好一些,不过程序结束时记得释放内存。看看DELPHI的帮助已经足够了,如果嫌慢,就来论坛跟大家切磋。
      

  8.   

    把s(: Tform;)设为全局的好一些,不过程序结束时记得释放内存。
    这样编译选项就不会影响你的代码逻辑了。看看DELPHI的帮助已经足够了,如果嫌慢,就来论坛跟大家切磋。
      

  9.   

    我已经吧S设为全局变量:   s:tform;
    书上说:
    与模式窗体不同的是,无法在代码中判断无模式窗体什么时候将删除。因此,无法在创建窗体实例的例程中删除窗体的实例。用户有可能在应用程序正在运行的任何时候关闭无模式窗体。因此,无模式窗体本身一定要把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过程?
      

  10.   

    使用CPU调试窗体,可以看到真正原因。或者 在begin后,加一句 ShowMessage(Integer(s)); 看看s里到底是什么?
      

  11.   

    动态也有办法,参考下面代码unit Unit1;interfaceuses
      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.
      

  12.   

    help上说..
    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);???
      

  13.   

    Tform,这里是不行的啦,要具体的窗体名了,而用这个窗体要全局变了的哦,再试试吧
      

  14.   

    procedure TForm1.Button1Click(Sender: TObject);
    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;