關於private,protected,public一問 |
尚未結案
|
aAlan
一般會員 發表:38 回覆:24 積分:12 註冊:2004-07-23 發送簡訊給我 |
請問各位大大:
在有●標註的地方,是屬於private,protected or public 呢?
如果屬於public的話,要如何讓這幾個procedure變成protected 或
private呢? unit Unit1; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
//****** dynamic link ****************************************
TShape = class
●procedure Draw; virtual; // need added a virtual directive
end; TRectangle = class(TShape)
●procedure Draw; override; // Object pascal can only override a virtual method
end; TEllipse = class(TShape)
●procedure Draw; override;
end;
//***********************************************************
var
Form1: TForm1; implementation {$R *.DFM}
procedure TShape.Draw;
begin
ShowMessage('執行 TShape.Draw ');
end;
procedure TRectangle.Draw;
begin
ShowMessage('執行 TRectangle.Draw ');
end;
procedure TEllipse.Draw;
begin
ShowMessage('執行 TEllipse.Draw ');
end; procedure TForm1.Button1Click(Sender: TObject);
var
myShape:TShape;
myRectangle:TRectangle ;
myEllipse:TEllipse;
begin
myShape := TShape.Create;
myShape.Draw;
myShape.Free; myRectangle := TRectangle.Create;
myRectangle.Draw;
myRectangle.Free; myEllipse := TEllipse.Create;
myEllipse.Draw;
myEllipse.Free;
end; end. 發表人 - aAlan 於 2004/07/26 21:39:09
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
應該是 published, 截自 help:
Members at the beginning of a class declaration that don急 have a specified visibility are by default published, provided the class is compiled in the {$M } state or is derived from a class compiled in the {$M } state; otherwise, such members are public.
如果想要宣告成 protected 或 private
就加個關鍵字 protected 或 private 即可
例:
TShape = class private // 宣告成 private procedure Draw; virtual; end; TRectangle = class(TShape) protected // 宣告成 protected procedure Draw; override; end;-- 向 KTop 的弟兄們致敬! |
richtop
資深會員 發表:122 回覆:646 積分:468 註冊:2003-06-10 發送簡訊給我 |
大家好: 誠如hagar版主所提供的說明:
引言:應該是 published, 截自 help: Members at the beginning of a class declaration that don急 have a specified visibility are by default published, provided the class is compiled in the {$M } state or is derived from a class compiled in the {$M } state; otherwise, such members are public.如果宣告前沒有編譯指令{$M },是不是有可能是public。 published fields or methods宣告的一個主要目的是希望在design-time,這些fields or methods會出現在Object Inspector上。 不知這樣的說法精不精確? |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |