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

我想每當 Assign 屬性值時機做些事情

尚未結案
Diviner
初階會員


發表:36
回覆:112
積分:34
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-04-19 11:25:29 IP:218.103.xxx.xxx 未訂閱
我目前 Inherit 了一個 ClientDataSet component, 我希望每次 Assign 一個 Value 到它的 CommandText 屬性時, 都去呼叫一個自定 Function 去做些事情, 該如何寫呢? 謝謝。 -- 小卜子
------
--
小卜子
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-04-19 11:30:33 IP:147.8.xxx.xxx 未訂閱
Override its SetCommandText method.
Diviner
初階會員


發表:36
回覆:112
積分:34
註冊:2002-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-04-19 15:41:38 IP:218.103.xxx.xxx 未訂閱
引言: Override its SetCommandText method.
是否 VCL Component 中每個 Property 都有一個相應的 SetXXXX 對應的呢? 那麼我 Inherit 出來的 TMyComponent, 由我加上的 Property, 是否最好都用 SetXXXX 來 Assign value 呢? -- 小卜子 發表人 - diviner 於 2004/04/19 15:43:24
------
--
小卜子
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-04-19 16:04:59 IP:147.8.xxx.xxx 未訂閱
It depends, try to take a look at the source for TCustomClientDataSet in DBClient.pas.
Diviner
初階會員


發表:36
回覆:112
積分:34
註冊:2002-03-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-04-19 18:09:13 IP:218.103.xxx.xxx 未訂閱
引言: It depends, try to take a look at the source for TCustomClientDataSet in DBClient.pas.
我看了一下 DBClient.pas, 發覺我正想動手 override 的 method SetDataSource 並無 virtual, 我可以 override 嗎? -- 小卜子 發表人 - diviner 於 2004/04/19 18:12:43
------
--
小卜子
James
高階會員


發表:10
回覆:290
積分:220
註冊:2002-07-25

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-04-19 18:48:26 IP:61.218.xxx.xxx 未訂閱
    type
  B = class(TClientDataSet)
  private
    function GetDataSource: TDatasource;
    procedure SetDataSource(const Value: TDatasource);
  public
    property MasterSource: TDatasource read GetDataSource write SetDataSource;
  end ;    function B.GetDataSource: TDatasource;
begin
  Result := inherited MasterSource;
  ShowMessage( 'Get' );
end;    procedure B.SetDataSource(const Value: TDatasource);
begin
  Inherited MasterSource := Value ;
  ShowMessage( 'Set' );
end;
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-04-20 10:27:09 IP:147.8.xxx.xxx 未訂閱
I think you can override its DataEvent (inherited from TDataSet) and look for deDataSetChange event.
Diviner
初階會員


發表:36
回覆:112
積分:34
註冊:2002-03-13

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-04-20 11:14:46 IP:218.103.xxx.xxx 未訂閱
引言:
type
  B = class(TClientDataSet)
  private
    function GetDataSource: TDatasource;
    procedure SetDataSource(const Value: TDatasource);
  public
    property MasterSource: TDatasource read GetDataSource write SetDataSource;
  end ;    function B.GetDataSource: TDatasource;
begin
  Result := inherited MasterSource;
  ShowMessage( 'Get' );
end;    procedure B.SetDataSource(const Value: TDatasource);
begin
  Inherited MasterSource := Value ;
  ShowMessage( 'Set' );
end;
原來 Property 可以 Inherited 的, 現在知道了, 謝謝你。我用了這方法解決了問題了。 -- 小卜子
------
--
小卜子
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#9 引用回覆 回覆 發表時間:2004-04-20 11:26:03 IP:147.8.xxx.xxx 未訂閱
引言:原來 Property 可以 Inherited 的, 現在知道了, 謝謝你。我用了這方法解決了問題了。
There is a potential problem with the above method. You are not overriding the property but actually hiding the inherited one. So when you typecast your object (e.g. TClientDataSet) and set its DataSource property, it is actullay using the TCustomDataSet method, not yours.
Diviner
初階會員


發表:36
回覆:112
積分:34
註冊:2002-03-13

發送簡訊給我
#10 引用回覆 回覆 發表時間:2004-04-20 11:35:05 IP:218.103.xxx.xxx 未訂閱
引言: I think you can override its DataEvent (inherited from TDataSet) and look for deDataSetChange event.
可否舉個例子, 我看不來, 功力不夠。 -- 小卜子
------
--
小卜子
Diviner
初階會員


發表:36
回覆:112
積分:34
註冊:2002-03-13

發送簡訊給我
#11 引用回覆 回覆 發表時間:2004-04-20 11:41:21 IP:218.103.xxx.xxx 未訂閱
引言:
引言:原來 Property 可以 Inherited 的, 現在知道了, 謝謝你。我用了這方法解決了問題了。
There is a potential problem with the above method. You are not overriding the property but actually hiding the inherited one. So when you typecast your object (e.g. TClientDataSet) and set its DataSource property, it is actullay using the TCustomDataSet method, not yours.
我確未想到這個, 我明白了, 因為無法做到 Late binding 的效果, 那麼請你繼續解說一下 deDataSetChange 的用法好嗎, DB.pas 中牽涉到 deDataSetChange 的程式碼不少, 看不來。 -- 小卜子
------
--
小卜子
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#12 引用回覆 回覆 發表時間:2004-04-20 12:26:00 IP:147.8.xxx.xxx 未訂閱
I have spent some time on tracing it and sorry to tell you that overring DataEvent is not a solution and all DataSource related functions are privated in TCustomClientDataSet 
Diviner
初階會員


發表:36
回覆:112
積分:34
註冊:2002-03-13

發送簡訊給我
#13 引用回覆 回覆 發表時間:2004-04-20 12:37:22 IP:218.103.xxx.xxx 未訂閱
引言: But you cannot only build your application as runtime packages then and this functionality will not work inside the IDE at design time. And what do you want to do with this change of DataSource?
謝謝您。但我不想它受到限制而不能作為 runtime packages。 我正建立一個 TMyClientDataSet, 我希望它能第一時間取得其 Master DataSet 的一些資料。那麼最好的時機, 應該就是當設定另一個 TMyClientDataSet 物件給它作為 Master Table 時 (也就是 Assign value 給它的 MasterSource 屬性時), 一併把 Master DataSet 的那些資料交給它了。 有沒有其他辦法呢? -- 小卜子
------
--
小卜子
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#14 引用回覆 回覆 發表時間:2004-04-20 15:04:42 IP:147.8.xxx.xxx 未訂閱
If you only what this function in TMyClientDataet then using James's method is fine. Otherwise, I think you need to modify TCustomClientDataSet in the VCL.
Diviner
初階會員


發表:36
回覆:112
積分:34
註冊:2002-03-13

發送簡訊給我
#15 引用回覆 回覆 發表時間:2004-04-20 15:57:03 IP:218.103.xxx.xxx 未訂閱
引言: If you only what this function in TMyClientDataet then using James's method is fine. Otherwise, I think you need to modify TCustomClientDataSet in the VCL.
不是不敢動 VCL, 只是覺得這得配合一些管理工作才行, 否則後人拿起我的 Source code 卻連 Compile 都作不了, 卻沒有很好的 Document 說明時, 他會無計可施呢, 那就很麻煩了。 那權用 James 的方法吧, 謝謝您。 -- 小卜子
------
--
小卜子
系統時間:2024-05-17 17:07:49
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!