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

如何動態宣告VCL元件?

尚未結案
WhiteFang
一般會員


發表:9
回覆:23
積分:6
註冊:2002-11-22

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-04-02 18:23:59 IP:163.28.xxx.xxx 未訂閱
請問該如何動態宣告VCL元件?他的理論原則是什麼? 有些元件需要如下的方法,Graphic位置的意義為何? Graphics::TBitmap* image=new Graphics::TBitmap(); 又TMemo、TPopupMenu這些要如何使用? 多謝!!
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-04-02 19:27:37 IP:61.221.xxx.xxx 未訂閱
引言: 請問該如何動態宣告VCL元件?他的理論原則是什麼? 有些元件需要如下的方法,Graphic位置的意義為何? Graphics::TBitmap* image=new Graphics::TBitmap(); 又TMemo、TPopupMenu這些要如何使用? 多謝!!
WhiteFang 你好:
(1)TBitmap 這個元件的宣告,是定義在 Graphics.hpp 檔案裡面,它的位置應
   該在 C:\Program Files\Borland\CBuilder6\Include\Vcl 這個目錄下,如
   果你看過這個檔案的內容,應該就會知道為什麼不是這樣寫??
   TBitmap *bmp=new TBitmap();
   而是應該這樣寫
   Graphics::TBitmap *bmp=new Graphics::TBitmap();
   沒錯,因為是 namespace 的問題,跟它原始的宣告方式有關的
(2)TMemo, TPopupMemo 該如何動態建立呢??
   其實所有的元件都是 class,以 C   的觀念來看,都是 new, delete 沒有
   其他特別之處,只不過,VCL 元件如果是看得見的元件,通常要加設 Parent
   這個屬性,如下: (其它的~~並沒有特別的差異之處,都是基本的 C   觀念)
   TMemo *memo=new TMemo(Application);
   memo->Parent=Form1;
   // 中間做你想要完成的事情
   delete memo;
-- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
WhiteFang
一般會員


發表:9
回覆:23
積分:6
註冊:2002-11-22

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-04-03 02:19:45 IP:163.28.xxx.xxx 未訂閱
再問個笨問題,請問 TMemo *memo=new TMemo(Application); memo->Parent=Form1; // 中間做你想要完成的事情 delete memo; 中TMemo(Application); 是什麼意思?為何要加Application呢?
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-04-03 08:41:42 IP:203.73.xxx.xxx 未訂閱
引言: 再問個笨問題,請問 TMemo *memo=new TMemo(Application); memo->Parent=Form1; // 中間做你想要完成的事情 delete memo; 中TMemo(Application); 是什麼意思?為何要加Application呢?
WhiteFang 你好: 你如果查詢過 TMemo 元件的 constructor 的話 應該就會知道,這樣寫 TMemo(Application) 代表指定 Application 是 TMemo 元件的 Owner Owner 是用來做什麼的呢?? 以下資料轉貼自 BCB Help,養成自己看文件的好習慣吧 < class="code"> TComponent::Owner Indicates the component that is responsible for streaming and freeing this component. __property TComponent* Owner = {read=FOwner}; Description Use Owner to find the owner of a component. The Owner of a component is responsible for two things: The memory for the owned component is freed when its owner's memory is freed. This means that when a form is destroyed, all the components on the form are also destroyed. The Owner is responsible for loading and saving the published properties of its owned controls. By default, a form owns all components that are on it. In turn, the form is owned by the application. Thus when the application shuts down and its memory is freed, the memory for all forms (and all their owned components) is also freed. When a form is loaded into memory, it loads all of the components that are on it. The owner of a component is determined by the parameter passed to the constructor when the component is created. For components created in the form designer, the form is automatically assigned as the Owner. Warning: If a component has an Owner other than a form or data module, it will not be saved or loaded with its Owner unless you identify it as a subcomponent. To identify a component as a subcomponent, call the SetSubComponent method. -- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
系統時間:2024-05-04 16:47:34
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!