線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1458
推到 Plurk!
推到 Facebook!

關於private,protected,public一問

尚未結案
aAlan
一般會員


發表:38
回覆:24
積分:12
註冊:2004-07-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-07-26 21:29:45 IP:140.113.xxx.xxx 未訂閱
請問各位大大: 在有●標註的地方,是屬於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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-07-26 22:56:16 IP:202.39.xxx.xxx 未訂閱
應該是 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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-07-26 23:50:44 IP:211.76.xxx.xxx 未訂閱
大家好:     誠如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上。 不知這樣的說法精不精確?
系統時間:2024-05-20 4:12:03
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!