Cria ção de novo componente

Delphi

08/05/2003

Como faço para criar um novo componente apartir de um componente já existente...tipo quero usar a grid, mas jah deixar programado para inserir os dados quando clicar na celula ou qdo o cursor chegar ali...
entaum feito isso quero q. seja um novo tipo de grid, ou um novo componente...como faço?

Para que qdo for inserir uma proxima grid no projeto eu informe o tipo dela e ela funcione de acordo com o tipo q. eu especifiquei.


Diana

Diana

Curtidas 0

Respostas

Rosivaldo

Rosivaldo

08/05/2003

Oi Diana, na ajuda do Delphi tem um bom exemplo de criação de componentes a partir de um já existente. Mas vou te dar uma adiantada de como fazer...

unit testeExecucao; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, FlatCheckBox; type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; FlatCheckBox1: TFlatCheckBox; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; type TMyEdit = class(TEdit) private FMaxLength: Integer; FOnChange: TNotifyEvent; procedure SetMaxLength(Valor: Integer); procedure Change; override; public property MaxLength: Integer read FMaxLength write SetMaxLength default 5; property OnChange: TNotifyEvent read FOnChange write FOnChange; constructor Create(owner : TComponent); reintroduce; end; var Form1: TForm1; implementation {$R *.DFM} constructor TMyEdit.Create(owner: TComponent); begin inherited create(owner); end; procedure TMyEdit.Change; begin ShowMessage(´Event handler´); inherited; end; procedure TMyEdit.SetMaxLength(Valor: Integer); begin if FMaxLength <> Valor then begin FMaxLength := Valor; if HandleAllocated then DoSetMaxLength(Valor); end; end; procedure TForm1.Button1Click(Sender: TObject); var MeuEdit: TMyEdit; begin MeuEdit := TMyEdit.Create(Self); MeuEdit.Parent := Self; MeuEdit.SetBounds(10, 50, 100,20); end; end.


Espero ter ajudado.


GOSTEI 0
POSTAR