自製元件、事件問題請教 |
尚未結案
|
老大仔
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:78 回覆:837 積分:1088 註冊:2006-07-06 發送簡訊給我 |
各位前輩好:
小弟最近在練一些自製元件的東西, 目前有個需求: 『該元件以Panel為底層,然後必須要有三個基本的按鈕(TBitBtn), 此三個按鈕也都必須在Panel中。 當開發人員將此元件拉到Form裡後: 1.Panel.Align必須預設alTop。 2.開發人員要能夠自由的移動該3個按鈕。 3.此元件拉到Form裡,要能夠讓開發人員自定該3個按鈕的各自onClick事件。 4.此元件要能夠讓開發人員再自行放入其他元件(TButton或是TEdit之類的)。』 現在都已經做的差不多了,但是針對第3項的Click事件要能夠獨立一事, 目前做的code大概如下, 但是只要一拉到Form之後,什麼事都不做,直接Run的話, 會出現Project Project1.exe raised exception class EComponentError with message 'A component named MyButton1 already exists'. Process stopped. Use Step or Run to continue. 的錯誤訊息。 小弟不才,不知道要怎麼改... 請問各位前輩這段要怎麼調整呢? [code delphi] type TMyAutoCreatePanel = class(TPanel) private { Private declarations } FMyButton1: TBitBtn; FMyButton2: TBitBtn; FMyButton3: TBitBtn; procedure OnBtnClick(Sender : TObject); protected { Protected declarations } public { Public declarations } constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure Click(); override; published { Published declarations } property OnClick; end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TMyAutoCreatePanel]); end; { TMyAutoCreatePanel } procedure TMyAutoCreatePanel.OnBtnClick(Sender : TObject); begin inherited Click; ShowMessage(TBitBtn(Sender).Name); end; constructor TMyAutoCreatePanel.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.Align := alTop; Self.Height := 27; //inherited OnClick := nil; FMyButton1 := TBitBtn.Create(AOwner); FMyButton1.Parent := Self; FMyButton1.Name := 'AAA'; FMyButton1.Top := 0; FMyButton1.Height := 25; FMyButton1.Left := 0; FMyButton1.Caption := 'AAA'; FMyButton1.OnClick := OnBtnClick; FMyButton2 := TBitBtn.Create(AOwner); FMyButton2.Parent := Self; FMyButton2.Name := 'BBB'; FMyButton2.Top := 0; FMyButton2.Height := 25; FMyButton2.Left := 74; FMyButton2.Caption := 'BBB'; FMyButton2.OnClick := OnBtnClick; FMyButton3 := TBitBtn.Create(AOwner); FMyButton3.Parent := Self; FMyButton3.Name := 'CCC'; FMyButton3.Top := 0; FMyButton3.Height := 25; FMyButton3.Left := 148; FMyButton3.Caption := 'CCC'; FMyButton3.OnClick := OnBtnClick; end; destructor TMyAutoCreatePanel.Destroy; begin inherited Destroy; end; procedure TMyAutoCreatePanel.Click; begin inherited Click; end; end. [/code] |
leveon
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:30 回覆:389 積分:303 註冊:2012-02-12 發送簡訊給我 |
FMyButton1 := TBitBtn.Create(AOwner);
改成 FMyButton1 := TBitBtn.Create(Self); ===================引 用 老大仔 文 章=================== 各位前輩好: 小弟最近在練一些自製元件的東西, 目前有個需求: 『該元件以Panel為底層,然後必須要有三個基本的按鈕(TBitBtn), 此三個按鈕也都必須在Panel中。 當開發人員將此元件拉到Form裡後: 1.Panel.Align必須預設alTop。 2.開發人員要能夠自由的移動該3個按鈕。 3.此元件拉到Form裡,要能夠讓開發人員自定該3個按鈕的各自onClick事件。 4.此元件要能夠讓開發人員再自行放入其他元件(TButton或是TEdit之類的)。』 現在都已經做的差不多了,但是針對第3項的Click事件要能夠獨立一事, 目前做的code大概如下, 但是只要一拉到Form之後,什麼事都不做,直接Run的話, 會出現Project Project1.exe raised exception class EComponentError with message 'A component named MyButton1 already exists'. Process stopped. Use Step or Run to continue. 的錯誤訊息。 小弟不才,不知道要怎麼改... 請問各位前輩這段要怎麼調整呢? [code delphi] type TMyAutoCreatePanel = class(TPanel) private { Private declarations } FMyButton1: TBitBtn; FMyButton2: TBitBtn; FMyButton3: TBitBtn; procedure OnBtnClick(Sender : TObject); protected { Protected declarations } public { Public declarations } constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure Click(); override; published { Published declarations } property OnClick; end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TMyAutoCreatePanel]); end; { TMyAutoCreatePanel } procedure TMyAutoCreatePanel.OnBtnClick(Sender : TObject); begin inherited Click; ShowMessage(TBitBtn(Sender).Name); end; constructor TMyAutoCreatePanel.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.Align := alTop; Self.Height := 27; //inherited OnClick := nil; FMyButton1 := TBitBtn.Create(AOwner); FMyButton1.Parent := Self; FMyButton1.Name := 'AAA'; FMyButton1.Top := 0; FMyButton1.Height := 25; FMyButton1.Left := 0; FMyButton1.Caption := 'AAA'; FMyButton1.OnClick := OnBtnClick; FMyButton2 := TBitBtn.Create(AOwner); FMyButton2.Parent := Self; FMyButton2.Name := 'BBB'; FMyButton2.Top := 0; FMyButton2.Height := 25; FMyButton2.Left := 74; FMyButton2.Caption := 'BBB'; FMyButton2.OnClick := OnBtnClick; FMyButton3 := TBitBtn.Create(AOwner); FMyButton3.Parent := Self; FMyButton3.Name := 'CCC'; FMyButton3.Top := 0; FMyButton3.Height := 25; FMyButton3.Left := 148; FMyButton3.Caption := 'CCC'; FMyButton3.OnClick := OnBtnClick; end; destructor TMyAutoCreatePanel.Destroy; begin inherited Destroy; end; procedure TMyAutoCreatePanel.Click; begin inherited Click; end; end. [/code] |
老大仔
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:78 回覆:837 積分:1088 註冊:2006-07-06 發送簡訊給我 |
leveon大大您好:
改成您的方式後,雖然可以Run,但是BitBtn的Click無法自定,會被強制指定到以下事件中。 這樣就不符合我要的"每個Button的onClick的事件要能夠獨立"需求了。 [code delphi] procedure TForm1.MyAutoCreatePanel1Click(Sender: TObject); begin end; [/code] ===================引 用 leveon 文 章=================== FMyButton1 := TBitBtn.Create(AOwner); 改成 FMyButton1 := TBitBtn.Create(Self);
編輯記錄
老大仔 重新編輯於 2017-02-16 17:59:09, 註解 無‧
|
leveon
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:30 回覆:389 積分:303 註冊:2012-02-12 發送簡訊給我 |
你的FMyButton1.OnClick := OnBtnClick;
當然是跑OnBtnClick的 要獨立的click事件當然是需要自己弄一個 private FMyButton1Click :TNotifyevent; public procedure myButton1Click(Sender: TObject); published property OnMyButton1Click: TNotifyevent read FMyButton1Click write FMyButton1Click; procedure TMyAutoCreatePanel.myButton1Click(Sender: TObject); begin if Assigned(FMyButton1Click) then OnMyButton1Click(Sender); end; FMyButton1. On Click : = myButton1Click; ===================引 用 老大仔 文 章=================== leveon大大您好: 改成您的方式後,雖然可以Run,但是BitBtn的Click無法自定,會被強制指定到以下事件中。 這樣就不符合我要的"每個Button的onClick的事件要能夠獨立"需求了。 [code delphi] procedure TForm1.MyAutoCreatePanel1Click(Sender: TObject); begin end; [/code] ===================引 用 leveon 文 章=================== FMyButton1 := TBitBtn.Create(AOwner); 改成 FMyButton1 := TBitBtn.Create(Self);
編輯記錄
leveon 重新編輯於 2017-02-16 20:52:44, 註解 無‧
|
老大仔
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:78 回覆:837 積分:1088 註冊:2006-07-06 發送簡訊給我 |
leveon 大大:
經測試,我將元件拉到Form後,對Button按下去後,還是指向到以下事件 procedure TForm1.MyAutoCreatePanel1Click(Sender: TObject); begin end; 另外, FMyButton1 := TBitBtn.Create(AOwner); 改成 FMyButton1 := TBitBtn.Create(Self); 之後,我的Button就不能自行任意移動了。 ===================引 用 leveon 文 章=================== 你的FMyButton1.OnClick := OnBtnClick; 當然是跑OnBtnClick的 要獨立的click事件當然是需要自己弄一個 private FMyButton1Click :TNotifyevent; public procedure myButton1Click(Sender: TObject); published property OnMyButton1Click: TNotifyevent read FMyButton1Click write FMyButton1Click; procedure TMyAutoCreatePanel.myButton1Click(Sender: TObject); begin if Assigned(FMyButton1Click) then OnMyButton1Click(Sender); end; FMyButton1. On Click : = myButton1Click; |
leveon
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:30 回覆:389 積分:303 註冊:2012-02-12 發送簡訊給我 |
看懂你要的了 把你原先的Code 改一下
還是不行的話 把你修改後完整的Code 貼上來吧 if (csDesigning in ComponentState) then begin FMyButton1 : = T Bit Btn.Create(AOwner); FMyButton1.Parent := Self; FMyButton1.Name : = 'AAA'; FMyButton1.Top := 0; FMyButton1.Height : = 25; FMyButton1.Left : = 0; FMyButton1.Caption : = 'AAA'; //FMyButton1.OnClick := OnBtnClick; 拿掉 end; ===================引 用 老大仔 文 章=================== leveon 大大: 經測試,我將元件拉到Form後,對Button按下去後,還是指向到以下事件 procedure TForm1.MyAutoCreatePanel1Click(Sender: TObject); begin end; 另外, FMyButton1 := TBitBtn.Create(AOwner); 改成 FMyButton1 := TBitBtn.Create(Self); 之後,我的Button就不能自行任意移動了。 ===================引 用 leveon 文 章=================== 你的FMyButton1.OnClick := OnBtnClick; 當然是跑OnBtnClick的 要獨立的click事件當然是需要自己弄一個 private FMyButton1Click :TNotifyevent; public procedure myButton1Click(Sender: TObject); published property OnMyButton1Click: TNotifyevent read FMyButton1Click write FMyButton1Click; procedure TMyAutoCreatePanel.myButton1Click(Sender: TObject); begin if Assigned(FMyButton1Click) then OnMyButton1Click(Sender); end; FMyButton1. On Click : = myButton1Click; |
老大仔
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:78 回覆:837 積分:1088 註冊:2006-07-06 發送簡訊給我 |
leveon大大:
還是不行... 我改成這樣後,在按下Run之後會有AccessViolation的錯誤訊息: Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0042BA58 in module 'Project1.exe'. Read of address 0000021C'. Process stopped. Use Step or Run to continue. 而且改成這樣的話會發生一個情況: 在開發人員設計初期是看的到按鈕 但是執行的時候按鈕應該會出不來(?) 以下是最後改後的code: (我只先針對AAA按鈕做修改,剩餘兩個按鈕故意先不改) [code delphi] type TMyAutoCreatePanel = class(TPanel) private { Private declarations } FMyButton1: TBitBtn; FMyButton2: TBitBtn; FMyButton3: TBitBtn; FMyButtonClick :TNotifyEvent; protected { Protected declarations } public { Public declarations } constructor Create(AOwner: TComponent); override; destructor Destroy; override; //procedure Click(); override; procedure BtnClick(Sender : TObject); published { Published declarations } property OnClick; property OnButnClick: TNotifyevent read FMyButtonClick write FMyButtonClick; end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TMyAutoCreatePanel]); end; { TMyAutoCreatePanel } procedure TMyAutoCreatePanel.BtnClick(Sender : TObject); begin //inherited Click; //ShowMessage(TBitBtn(Sender).Name); if Assigned(FMyButtonClick) then OnButnClick(Sender); end; constructor TMyAutoCreatePanel.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.Align := alTop; Self.Height := 27; if (csDesigning in ComponentState) then begin //FMyButton1 := TBitBtn.Create(Self); FMyButton1 := TBitBtn.Create(AOwner); FMyButton1.Parent := Self; FMyButton1.Name := 'AAA'; FMyButton1.Top := 0; FMyButton1.Height := 25; FMyButton1.Left := 0; FMyButton1.Caption := 'AAA'; //FMyButton1.OnClick := BtnClick; end; FMyButton2 := TBitBtn.Create(Self); //FMyButton2 := TBitBtn.Create(AOwner); FMyButton2.Parent := Self; FMyButton2.Name := 'BBB'; FMyButton2.Top := 0; FMyButton2.Height := 25; FMyButton2.Left := 74; FMyButton2.Caption := 'BBB'; FMyButton2.OnClick := BtnClick; FMyButton3 := TBitBtn.Create(Self); //FMyButton3 := TBitBtn.Create(AOwner); FMyButton3.Parent := Self; FMyButton3.Name := 'CCC'; FMyButton3.Top := 0; FMyButton3.Height := 25; FMyButton3.Left := 148; FMyButton3.Caption := 'CCC'; FMyButton3.OnClick := BtnClick; end; destructor TMyAutoCreatePanel.Destroy; begin inherited Destroy; end; end. [/code] ===================引 用 leveon 文 章=================== 看懂你要的了 把你原先的Code 改一下 還是不行的話 把你修改後完整的Code 貼上來吧 if (csDesigning in ComponentState) then begin FMyButton1 : = T Bit Btn.Create(AOwner); FMyButton1.Parent := Self; FMyButton1.Name : = 'AAA'; FMyButton1.Top := 0; FMyButton1.Height : = 25; FMyButton1.Left : = 0; FMyButton1.Caption : = 'AAA'; //FMyButton1.OnClick := OnBtnClick; 拿掉 end; ===================引 用 老大仔 文 章=================== leveon 大大: 經測試,我將元件拉到Form後,對Button按下去後,還是指向到以下事件 procedure TForm1.MyAutoCreatePanel1Click(Sender: TObject); begin end; 另外, FMyButton1 := TBitBtn.Create(AOwner); 改成 FMyButton1 := TBitBtn.Create(Self); 之後,我的Button就不能自行任意移動了。
編輯記錄
老大仔 重新編輯於 2017-02-17 12:06:38, 註解 無‧
|
leveon
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:30 回覆:389 積分:303 註冊:2012-02-12 發送簡訊給我 |
type
TMyAutoCreatePanel = class(TPanel) private { Private declarations } FMyButton1: TBitBtn; FMyButton2: TBitBtn; FMyButton3: TBitBtn; protected { Protected declarations } public { Public declarations } constructor Create(AOwner: TComponent); override; destructor Destroy; override; published { Published declarations } end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TMyAutoCreatePanel]); end; { TMyAutoCreatePanel } constructor TMyAutoCreatePanel.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.Align := alTop; Self.Height := 27; if (csDesigning in ComponentState) then begin FMyButton1 := TBitBtn.Create(AOwner); FMyButton1.Parent := Self; FMyButton1.Name := 'AAA'; FMyButton1.Top := 0; FMyButton1.Height := 25; FMyButton1.Left := 0; FMyButton1.Caption := 'AAA'; FMyButton2 := TBitBtn.Create(AOwner); FMyButton2.Parent := Self; FMyButton2.Name := 'BBB'; FMyButton2.Top := 0; FMyButton2.Height := 25; FMyButton2.Left := 74; FMyButton2.Caption := 'BBB'; FMyButton3 := TBitBtn.Create(AOwner); FMyButton3.Parent := Self; FMyButton3.Name := 'CCC'; FMyButton3.Top := 0; FMyButton3.Height := 25; FMyButton3.Left := 148; FMyButton3.Caption := 'CCC'; end; end; destructor TMyAutoCreatePanel.Destroy; begin inherited Destroy; end; end. end. ===================引 用 老大仔 文 章=================== leveon大大: 還是不行... 我改成這樣後,在按下Run之後會有AccessViolation的錯誤訊息: Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0042BA58 in module 'Project1.exe'. Read of address 0000021C'. Process stopped. Use Step or Run to continue. 而且改成這樣的話會發生一個情況: 在開發人員設計初期是看的到按鈕 但是執行的時候按鈕應該會出不來(?) 以下是最後改後的code: (我只先針對AAA按鈕做修改,剩餘兩個按鈕故意先不改) |
老大仔
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:78 回覆:837 積分:1088 註冊:2006-07-06 發送簡訊給我 |
leveon大大:
可以了!!!居然可以了!!!感動~~~~ 另外,我想問個從此元件中的延伸問題。 可以事先指定某個Button的onClick事件嗎? 可是該Button的onClick事件一樣要能夠在設計初期讓開發者修改 舉例來說~ FMyButton1的onClick事件預設為: ShowMessage('AAA'); 當使用者將這個Panel拉到Form中,點了FMyButton1兩下進入OnClick事件, 要出現ShowMessage('AAA'); 同時也要能夠讓開發者繼續在此事件中鍵入要做的事情 大概是這樣,不知是否可達到這樣的效果? ===================引 用 leveon 文 章=================== type TMyAutoCreatePanel = class(TPanel) private { Private declarations } FMyButton1: TBitBtn; FMyButton2: TBitBtn; FMyButton3: TBitBtn; protected { Protected declarations } public { Public declarations } constructor Create(AOwner: TComponent); override; destructor Destroy; override; published { Published declarations } end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TMyAutoCreatePanel]); end; { TMyAutoCreatePanel } constructor TMyAutoCreatePanel.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.Align := alTop; Self.Height := 27; if (csDesigning in ComponentState) then begin FMyButton1 := TBitBtn.Create(AOwner); FMyButton1.Parent := Self; FMyButton1.Name := 'AAA'; FMyButton1.Top := 0; FMyButton1.Height := 25; FMyButton1.Left := 0; FMyButton1.Caption := 'AAA'; FMyButton2 := TBitBtn.Create(AOwner); FMyButton2.Parent := Self; FMyButton2.Name := 'BBB'; FMyButton2.Top := 0; FMyButton2.Height := 25; FMyButton2.Left := 74; FMyButton2.Caption := 'BBB'; FMyButton3 := TBitBtn.Create(AOwner); FMyButton3.Parent := Self; FMyButton3.Name := 'CCC'; FMyButton3.Top := 0; FMyButton3.Height := 25; FMyButton3.Left := 148; FMyButton3.Caption := 'CCC'; end; end; destructor TMyAutoCreatePanel.Destroy; begin inherited Destroy; end; end. end.
編輯記錄
老大仔 重新編輯於 2017-02-17 15:01:34, 註解 無‧
|
leveon
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:30 回覆:389 積分:303 註冊:2012-02-12 發送簡訊給我 |
原Code不變 加入下方的Code
type TBitBtn = class(TButton) procedure Click; override; end; TMyAutoCreatePanel = class(TPanel) ............ procedure TBitBtn.Click; begin if Name='AAA' then showmessage('AAA') else if Name='BBB' then showmessage('BBB') else if Name='CCC' then showmessage('CCC'); inherited; end; ===================引 用 老大仔 文 章=================== leveon大大: 可以了!!!居然可以了!!!感動~~~~ 另外,我想問個從此元件中的延伸問題。 可以事先指定某個Button的onClick事件嗎? 可是該Button的onClick事件一樣要能夠在設計初期讓開發者修改 舉例來說~ FMyButton1的onClick事件預設為: ShowMessage('AAA'); 當使用者將這個Panel拉到Form中,點了FMyButton1兩下進入OnClick事件, 要出現ShowMessage('AAA'); 同時也要能夠讓開發者繼續在此事件中鍵入要做的事情 大概是這樣,不知是否可達到這樣的效果? |
老大仔
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:78 回覆:837 積分:1088 註冊:2006-07-06 發送簡訊給我 |
to leveon大大:
這個方式好像無效 另外,假如以此方式的話,那麼就無法達到我要的功能: 1.事先指定某個Button的onClick事件 2.該Button的onClick事件一樣要能夠在設計初期讓開發者修改 舉例來說~ FMyButton1的onClick事件預設為: ShowMessage('AAA'); 當使用者將這個Panel拉到Form中,點了FMyButton1兩下進入OnClick事件, 要出現ShowMessage('AAA'); 同時也要能夠讓開發者繼續在此事件中鍵入要做的事情 大概是這樣,不知是否可達到這樣的效果?
編輯記錄
老大仔 重新編輯於 2017-02-17 16:51:10, 註解 無‧
|
leveon
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:30 回覆:389 積分:303 註冊:2012-02-12 發送簡訊給我 |
1.上方Code無效?
2.意思就是當你在Design time的時候,按下button Click,這時馬上對編輯器 貼上Showmessage('AAA')的程式碼 用OTA是可以做到,但從沒看過有人在Delphi中這樣設計 ===================引 用 老大仔 文 章=================== to leveon大大: 這個方式好像無效 另外,假如以此方式的話,那麼就無法達到我要的功能: 1.事先指定某個Button的onClick事件 2.該Button的onClick事件一樣要能夠在設計初期讓開發者修改 舉例來說~ FMyButton1的onClick事件預設為: ShowMessage('AAA'); 當使用者將這個Panel拉到Form中,點了FMyButton1兩下進入OnClick事件, 要出現ShowMessage('AAA'); 同時也要能夠讓開發者繼續在此事件中鍵入要做的事情 大概是這樣,不知是否可達到這樣的效果? |
老大仔
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:78 回覆:837 積分:1088 註冊:2006-07-06 發送簡訊給我 |
to leveon大大:
1.嗯 剛剛測試沒反應@@ 2.沒錯~大至上是這樣~ 感覺上這個工程好像比較大一點 那這段我放棄好了XD 先能達到我要的基本功能(一開始上述的那些)這樣就好~ ===================引 用 leveon 文 章=================== 1.上方Code無效? 2.意思就是當你在Design time的時候,按下button Click,這時馬上對編輯器 貼上Showmessage('AAA')的程式碼 用OTA是可以做到,但從沒看過有人在Delphi中這樣設計 |
leveon
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:30 回覆:389 積分:303 註冊:2012-02-12 發送簡訊給我 |
1.沒反應?把整段Code貼上來吧
2.設計良好的GUI元件 OTA是跑不掉的 給你個連結從這邊開始 http://www.delphisources.ru/pages/faq/master-delphi-7/content/LiB0098.html 不過看你的OO pascal 基本觀念不是很清楚 片段碼貼給你似乎也無法理解 建議先不要管這些了 先找一些基礎的東西看看再說吧 ===================引 用 老大仔 文 章=================== to leveon大大: 1.嗯 剛剛測試沒反應@@ 2.沒錯~大至上是這樣~ 感覺上這個工程好像比較大一點 那這段我放棄好了XD 先能達到我要的基本功能(一開始上述的那些)這樣就好~ ===================引 用 leveon 文 章=================== 1.上方Code無效? 2.意思就是當你在Design time的時候,按下button Click,這時馬上對編輯器 貼上Showmessage('AAA')的程式碼 用OTA是可以做到,但從沒看過有人在Delphi中這樣設計 |
JL9168
中階會員 ![]() ![]() ![]() 發表:133 回覆:223 積分:76 註冊:2011-09-29 發送簡訊給我 |
這個需求有些地方是相互衝突的
1.建立元件的目的多半都是需要元件獨立掌控全局,以降低外在的干擾因素。 2.利用Create(AOwner)的方式的意義,代表將主導權交給IDE;元件的掌控力變得不是很可靠; 試想,如果IDE要刪除原有的三個按鈕,可是Panel元件不允許刪除,又該由誰(IDE or Panel)決定? 3.元件的主導權決定了元件的基礎與可靠度,以現有的需求來看有很多衝突;即使硬寫也會寫得很辛苦; 建議如下. (1).Panel上的預定三個按鈕應該是在Panel當中寫死,由Panel負責維護釋放;至於OnClick的處理,可以在Panel內統一導向一個事件來處理,只要該事件能分辨出Btn01,Btn02或Btn03然後再分派事件處理的流程就可以了。 (2).在Panel的屬性之中放入Btn01,Btn02和Btn03;藉由自定義的相關屬性來達到元件內改變按鈕大小、文字、位置和形狀的屬性,來達到移動與改變原有按鈕的其他相關屬性 |
JL9168
中階會員 ![]() ![]() ![]() 發表:133 回覆:223 積分:76 註冊:2011-09-29 發送簡訊給我 |
|
JL9168
中階會員 ![]() ![]() ![]() 發表:133 回覆:223 積分:76 註冊:2011-09-29 發送簡訊給我 |
|
JL9168
中階會員 ![]() ![]() ![]() 發表:133 回覆:223 積分:76 註冊:2011-09-29 發送簡訊給我 |
|
JL9168
中階會員 ![]() ![]() ![]() 發表:133 回覆:223 積分:76 註冊:2011-09-29 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |