var
  FTP : TNMFTP;
implementation
....Procedure CreateFTP;
begin
   if ??? then FTP := TNMFTP.Create(Nil);
end;???处怎么写才能让程序实现:如果已经执行过FTP := TNMFTP.Create(Nil);就不执行了,如果没有执行过,就执行Create.

解决方案 »

  1.   

    加一个记数器, 实例变量记数.if i<=0 then
       FTP := TNMFTP.Create(Nil);
    i:= i+1;
    destroy时, i:= i-1;
      

  2.   

    if not assigned(ftp) then FTP := TNMFTP.Create(Nil);
      

  3.   

    楼上,不对,不管Create过没有,assigned(ftp) 始终为True
      

  4.   

    var
      FTP : TNMFTP;
    implementation
    ....Procedure CreateFTP;
    begin
       if not assigned(ftp) then FTP := TNMFTP.Create(Nil);////////
    end;
    initialization 
      FTP:=nil;///////
      

  5.   

    多谢,楼上。如果有比Assigned更直接的函数就好了。
    这样的话
    procedure FreeFTP;
    begin
      FTP.Free;
      还得加一句:
      FTP := Nil;
    end;
      

  6.   

    if Assigned(TnmFtp) then FTP := TNMFTP.Create(Nil);
      

  7.   

    错了, if Not Assigned(Ftp) then Ftp := TnmFtp.Create(self);
      

  8.   

    >>  FTP.Free;
      还得加一句:
      FTP := Nil;
    --->
    FreeAndNil(FTP);
      

  9.   


    if not assigned(tt) then
    Try
      tt := TClass.Create(nil)
    finally
      tt.Free;
    end;
      

  10.   

    if FTP=nil then
    //FTP没有Create
      

  11.   

    注意FTP有释放的时候用FreeAndNil(FTP)
    或FTP.Free;
      FTP:=nil;
      

  12.   

    if Ftp=nil then TFtp.Create();
      

  13.   

    呵呵,
    同意 blazingfire(烈焰) 
    if FTP = Nil then FTP := TClass.Create(Application);FreeAndNil(FTP);