日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

class function或class procedure是什么意思

發布時間:2023/11/27 生活经验 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 class function或class procedure是什么意思 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

類函數\類過程.?? 它們是直接操作在類上面(沒有實例化的對象)???

下面是Delphi??? Help??? 的描述???
????
?? A class method is a method (other than a constructor) that operates on classes instead of objects. The definition of a class method must begin with the reserved word?
?? class. For example,???

?? type???
??? TFigure = class???
??? public???
???? class function Supports(Operation: string): Boolean; virtual;???
???? class procedure GetInfo(var Info: TFigureInfo); virtual;???
???? ...???
??? end;???

?? The defining declaration of a class method must also begin with class. For example,???

?? class procedure TFigure.GetInfo(var Info: TFigureInfo);???
?? begin???
??? ...???
?? end;???

?? In the defining declaration of a class method, the identifier Self represents the class where the method is called (which could be a descendant of the class in which it is defined). If the method is called in the class C, then Self is of the type class of C. Thus you cannot use Self to access fields, properties, and normal (object) methods, but you can use it to call constructors and other class methods.???

?? A class method can be called through a class reference or an object reference. When it is called through an object reference, the class of the object becomes the value of Self.


類方法(Class methods)是一類特殊的方法,它們在聲明時要以 class 開頭:
??? type
????  TFigure = class
??   public
??   ...
   class procedure GetInfo(var Info: TFigureInfo); virtual;
????   ...
???  end;
  實現時也以 class 開頭:
 class procedure TFigure.GetInfo(var Info: TFigureInfo); 
 begin
  ...
  end;
  乍一看好象平時沒有遇到過這個東東,好象這個東東也沒有什么大作用,其實不然。比如我們有時為輸入密碼或其他常用數據專門做一個 Form,但由于其代碼都在 Form 定義的 unit 里面,所以在使用時僅僅需要幾行代碼,比如:
??? with TfrmPassword.Create(nil) do
??? try
  ShowModal;
 finally
 Free;
 end;
??? 雖然這樣的代碼已經很簡潔,但如果寫多了還是很討厭的。利用類方法可以使其更簡潔:
??? TfrmPassword = class(TForm) 
??  ...  
??? public {Public declarations }  
??? class function Execute: TModalResult;  
??? end; 
??  ...
 class function TfrmPassword.Execute: TModalResult; 
 begin
  with TfrmPassword.Create(nil) do 
???  try
?????  Result :=ShowModal; 
???  finally
???   Release; //注意此處必須為release不能為free! 
???  end; 
??? end; 
 然后只用一行 TfrmPassword.Execute; 即可直接完成調用!

轉載于:https://www.cnblogs.com/lzj1981/archive/2013/04/28/3049419.html

總結

以上是生活随笔為你收集整理的class function或class procedure是什么意思的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。