在BCB中該如何Redeclaring VCL元件 |
答題得分者是:dllee
|
TheMoon
中階會員 發表:17 回覆:95 積分:67 註冊:2002-06-05 發送簡訊給我 |
想在現有元件中增加屬性,
但不想以新增元件的方式來做,
查看過之前的文章,
在 http://delphi.ktop.com.tw/topic.php?topic_id=24762 裡,
RaynorPao大大所提供的網址
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20327766.html
有提到以下作法:
Meikl, you could do that without creating new comonent. Redeclaring the TEdit class with new property will overide the TEdit class, and then you can simply add new property without creating new component. Here's the example, it's similar with Meikl example, but without force you to create new component.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TEdit = class(StdCtrls.TEdit) private FAlignment : TAlignment; procedure SetAlignment(Value: TAlignment); protected procedure CreateParams(var Params: TCreateParams); override; public property Alignment: TAlignment read FAlignment write SetAlignment; end; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TEdit.CreateParams(var Params: TCreateParams); const Alignments : array[TAlignment] of LongWord= (ES_Left,ES_Right, ES_Center); begin inherited CreateParams(Params); Params.Style := Params.Style or Alignments[FAlignment]; end; procedure TEdit.SetAlignment(Value: TAlignment); begin if FAlignment <> Value then begin FAlignment := Value; RecreateWnd; end; end; procedure TForm1.Button1Click(Sender: TObject); begin Edit1.Alignment := taRightJustify; end;想請問各位大大, 在BCB中該如何做呢? Thanks |
dllee
站務副站長 發表:321 回覆:2519 積分:1711 註冊:2002-04-15 發送簡訊給我 |
以我個人的經驗,在BCB中應該是不行的...
那樣的作法,我試過請參考:
■如何更新內建 VCL 元件
http://delphi.ktop.com.tw/topic.php?topic_id=18519
此法只能在 Delphi 中使用,在 BCB 應該是不行的(至少我用的 BCB5 是不行的)。 視動科技 VMASK - ViewMove Automation Software Kernel 發表人 - dllee 於 2004/08/25 05:31:44
------
http://www.ViewMove.com |
TheMoon
中階會員 發表:17 回覆:95 積分:67 註冊:2002-06-05 發送簡訊給我 |
引言: 以我個人的經驗,在BCB中應該是不行的... 那樣的作法,我試過請參考: ■如何更新內建 VCL 元件 http://delphi.ktop.com.tw/topic.php?topic_id=18519 此法只能在 Delphi 中使用,在 BCB 應該是不行的(至少我用的 BCB5 是不行的)。 視動科技 VMASK - ViewMove Automation Software Kernel 發表人 - dllee 於 2004/08/25 05:31:44Thank you a lot! 看來還是得新增元件了。 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |