zoukankan      html  css  js  c++  java
  • assigned(对象名)判断对象有没有被实例化?

    assigned 是用来判断某一指针(pointer)或过程引用是否为nil(空),如果为空则返回假(false)。
    用法示例(防止窗体被实例化多次):


    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;

    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    uses Unit2;

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if (Not assigned(form2)) then
      begin
        form2:=Tform2.Create(Self);
      end;
      form2.show;
    end;

    end.

    -----------------------
    unit Unit2;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;

    type
      TForm2 = class(TForm)
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form2: TForm2;

    implementation

    {$R *.dfm}

    procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Action:=caFree;
      form2:=nil;  //这句比较重要,窗体被释放时,窗体变量并不会自动变空
    end;

    end.

  • 相关阅读:
    批量转外部样式为行内样式
    AngularJS 笔记2
    windows特殊文件或文件夹
    zepto 入门
    js闭包
    AngularJS 笔记1
    sublime配置 sublimecondeintel 分号后不要提示
    sublime插件开发手记
    用flvplayer.swf在网页中播放视频(网页中flash视频播放的实现)
    无插件启动谷歌浏览器
  • 原文地址:https://www.cnblogs.com/jshchg/p/1929891.html
Copyright © 2011-2022 走看看