全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:845
推到 Plurk!
推到 Facebook!

請問如何設定元件中屬性的預設值

尚未結案
88090103
一般會員


發表:4
回覆:8
積分:2
註冊:2003-04-18

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-08 13:04:29 IP:61.219.xxx.xxx 未訂閱
請問如何在自己撰寫的元件屬性中設定預設值,我試過下列兩種方法,可是都不儘完美。 方法一、 __published: __property float DeviceVolt=read=FVolt,write=SetVolt ,default=1.2}; 方法二、 __fastcall TMyPowerSupply::TMyPowerSupply(TComponent* Owner) : TComponent(Owner) { FVolt = 1.2; } 另外,如果我的資料型態是「自定型別」又要如何設定,如下面所示的TDeviceStatus。 typedef enum DeviceStatusTag{ dsCLOSE, dsOPEN }TDeviceStatus;
------
Carlos Lin
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-05-26 20:38:37 IP:61.224.xxx.xxx 未訂閱
以下資料取自 BCB5 Online Help
引言: Default property values ---------------------------------------------------------------- When you declare a property, you can specify a default value for it. C Builder uses the default value to determine whether to store the property in a form file. If you do not specify a default value for a property, C Builder always stores the property. To declare a default value for a property, append an equal sign after the property name and a set of braces that holds the default keyword and the default value. For example, __property bool IsTrue = {default=true}; Note: Declaring a default value does not set the property to that value. The component's constructor method should initialize property values when appropriate. However, since objects always initialize their data members to 0, it is not strictly necessary for the constructor to set integer properties to 0, string properties to null, or Boolean properties to false.
如紅色部分所示,您必需在建構元中自己設定初值,也就是您所寫的方法一及方法二必需「一起使用」才有效。 基本上我的定義是,那個 default 是給說明文件用的,事實上,您可以故意亂搞,在 default 上寫一個值,在建構元寫另一個值,這都是可以的,compile 都會過! 我的建議是,除非的真是要買錢的元件,否則就省了吧,反正是以建構元為主。 您另外問到「自定型別」我想,是一樣的。 沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com
88090103
一般會員


發表:4
回覆:8
積分:2
註冊:2003-04-18

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-05-27 09:09:08 IP:61.219.xxx.xxx 未訂閱
Thanks for your information, I will try it.
------
Carlos Lin
系統時間:2024-05-03 10:40:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!