Adicionar propriedade num componente Timage
16/01/2013
0
Estou precisando criar um componente herdado do TImage e adicionar nele as propriedades para conectar à um ImageList com opção de ImageIndex.
Alguem poderia me ajudar. Eu tinha um componente como esse para delphi 7 (AbfComponents), porém ele não é compativel com o xe2.
Obrigado Pessoal.
Bruno Bonato
Posts
16/01/2013
Leonardo Centenaro
16/01/2013
Bruno Bonato
Como eu faria.
Obrigado.
17/01/2013
Rodolpho Silva
TMinhaImg = class(TImage) private FMinhaProp: String; public published property MinhaProp: String read FMinhaProp write FMinhaProp; end;
18/01/2013
Bruno Bonato
TMinhaImg = class(TImage) private FMinhaProp: String; public published property MinhaProp: String read FMinhaProp write FMinhaProp; end;
Obrigado Rodolfo
Só preciso saber como implementar as procedures.
Obrigado novamente
18/01/2013
Marco Salles
Estou precisando criar um componente herdado do TImage e adicionar nele as propriedades para conectar à um ImageList com opção de ImageIndex.
Alguem poderia me ajudar. Eu tinha um componente como esse para delphi 7 (AbfComponents), porém ele não é compativel com o xe2.
Obrigado Pessoal.
Class helper não lhe serve ?? Vc esta criando um novo componente somente pq precisa de algumas funcionalidades , a Class Helph lhe permite estender a propriedades sem ter que criar um novo componente , sem ter que instalar pacotes , compilar .. enfim
claro que vc tera o mesmo problema em saber como implementar as procedures..
18/01/2013
Bruno Bonato
Obrigado.
unit ImageL; interface uses Classes, Controls, Graphics, Vcl.ExtCtrls, Vcl.ImgList, System.Types, System.SysUtils; type TImageL = class(TImage) private { Private declarations } FImages: TCustomImageList; FImageIndex: TImageIndex; FImageChangeLink: TChangeLink; procedure SetImages(const Value: TCustomImageList); procedure SetImageIndex(const Value: TImageIndex); procedure ImageListChange(Sender: TObject); protected { Protected declarations } procedure Paint; override; public { Public declarations } constructor Create(AOwner: TComponent); override; destructor Destroy; override; published { Published declarations } property Images: TCustomImageList read FImages write SetImages; property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1; end; procedure Register; implementation { TMHLStaticTip } procedure Register; begin RegisterComponents('Standard', [TImageL]); end; constructor TImageL.Create(AOwner: TComponent); begin inherited Create(AOwner); FImageIndex := -1; FImageChangeLink := TChangeLink.Create; FImageChangeLink.OnChange := ImageListChange; end; destructor TImageL.Destroy; begin FreeAndNil(FImageChangeLink); inherited Destroy; end; procedure TImageL.Paint; var Rect: TRect; ImageWidth, ImageHeight: Integer; ImageTop, ImageLeft: Integer; begin inherited; Rect := ClientRect; if Assigned(Images) and (FImageIndex >= 0) then begin ImageWidth := FImages.Width; ImageHeight := FImages.Height; ImageLeft := Rect.Left; ImageTop := Rect.Top + ((Height - ImageHeight) div 2); Images.Draw(Canvas, ImageLeft, ImageTop, FImageIndex); end; end; procedure TImageL.SetImages(const Value: TCustomImageList); begin if Value <> FImages then begin if Assigned(FImages) then begin FImages.UnRegisterChanges(FImageChangeLink); FImages.RemoveFreeNotification(Self); end; FImages := Value; if Assigned(FImages) then begin FImages.RegisterChanges(FImageChangeLink); FImages.FreeNotification(Self); end; Invalidate; end; end; procedure TImageL.SetImageIndex(const Value: TImageIndex); begin if FImageIndex <> Value then begin FImageIndex := Value; Invalidate; end; end; procedure TImageL.ImageListChange(Sender: TObject); begin if Sender = Images then Self.Paint; end; end.
Clique aqui para fazer login e interagir na Comunidade :)