delhpi語法問題 |
答題得分者是:Coffee
|
inglong
初階會員 發表:28 回覆:27 積分:36 註冊:2004-08-13 發送簡訊給我 |
|
adonis
高階會員 發表:140 回覆:258 積分:159 註冊:2002-04-15 發送簡訊給我 |
inglong,您好
請參考 http://blog.csdn.net/coffeemay/archive/2006/09/23/1267628.aspx 我也在學習中,若有錯謬請見諒 ~ ===================引 用 inglong 文 章=================== 請問 DoDblClick : procedure of object ; 是什麼意思 跟procedure DoDbClick ;? 不同在哪裡? 第一次看到這樣的寫法
------
我也在努力學習中,若有錯謬請見諒。 |
Coffee
版主 發表:31 回覆:878 積分:561 註冊:2006-11-15 發送簡訊給我 |
DoDblClick : procedure of object ;
屬於物件的程序 procedure DoDbClick ; 一般程序 意指被描述為of object的函式是屬於類別函式,與一般的函式不同。 在Delphi中,類別函式指標是無法指向一般函式 因此of object被用來指該函式是類別函式 以下為Delphi 7 Help(keyword : of object): Procedural types allow you to treat procedures and functions as values that can be assigned to variables or passed to other procedures and functions. For example, suppose you define a function called Calc that takes two integer parameters and returns an integer: function Calc(X,Y: Integer): Integer; You can assign the Calc function to the variable F: var F: function(X,Y: Integer): Integer; F := Calc; If you take any procedure or function heading and remove the identifier after the word procedure or function, what's left is the name of a procedural type. You can use such type names directly in variable declarations (as in the previous example) or to declare new types: type TIntegerFunction = function: Integer; TProcedure = procedure; TStrProc = procedure(const S: string); TMathFunc = function(X: Double): Double; var F: TIntegerFunction; { F is a parameterless function that returns an integer } Proc: TProcedure; { Proc is a parameterless procedure } SP: TStrProc; { SP is a procedure that takes a string parameter } M: TMathFunc; { M is a function that takes a Double (real) parameter and returns a Double } procedure FuncProc(P: TIntegerFunction); { FuncProc is a procedure whose only parameter is a parameterless integer-valued function } The previous variables are all procedure pointers--that is, pointers to the address of a procedure or function. If you want to reference a method of an instance object (see Classes and objects), you need to add the words of object to the procedural type name. For example type TMethod = procedure of object; TNotifyEvent = procedure(Sender: TObject) of object; These types represent method pointers. A method pointer is really a pair of pointers; the first stores the address of a method, and the second stores a reference to the object the method belongs to. Given the declarations type TNotifyEvent = procedure(Sender: TObject) of object; TMainForm = class(TForm) procedure ButtonClick(Sender: TObject); ... end; var MainForm: TMainForm; OnClick: TNotifyEvent we could make the following assignment. OnClick := MainForm.ButtonClick; Two procedural types are compatible if they have the same calling convention, the same return value (or no return value), and the same number of parameters, with identically typed parameters in corresponding positions. (Parameter names do not matter.) Procedure pointer types are always incompatible with method pointer types. The value nil can be assigned to any procedural type. Nested procedures and functions (routines declared within other routines) cannot be used as procedural values, nor can predefined procedures and functions. If you want to use a predefined routine like Length as a procedural value, write a wrapper for it: function FLength(S: string): Integer; begin Result := Length(S); end;
------
不論是否我發的文,在能力範圍皆很樂意為大家回答問題。 為了補我的能力不足之處,以及讓答案可以被重複的使用,希望大家能儘量以公開的方式問問題。 在引述到我的文時自然會儘量替各位想辦法,謝謝大家! |
syntax
尊榮會員 發表:26 回覆:1139 積分:1258 註冊:2002-04-23 發送簡訊給我 |
|
Coffee
版主 發表:31 回覆:878 積分:561 註冊:2006-11-15 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |