Saber quando as propriedades da Action foram trocadas
Olá!
Criei um componente que herda da classe TCustomPanel, e que ele possui uma propriedade ´Action´ que é o do tipo TAction e também possui um TImage, sendo que este TImage eu faço receber a imagem que está na Action (Action -> TActionList -> Images(TImageList) ). Bom, até aí tudo bem, o meu problema é que quando mudo a propriedade ´Action.ImageIndex´, não consigo atualizar automaticamente a imagem do TImage.
Como faço para saber quando as propriedades da Action foram trocadas?
Obs.: atribuo a imagem da Action para o TImage no evento ´Paint´ do meu componente, mas ele não executa o ´Paint´ a todo momento.
Utilizo o Delphi 2007.
Criei um componente que herda da classe TCustomPanel, e que ele possui uma propriedade ´Action´ que é o do tipo TAction e também possui um TImage, sendo que este TImage eu faço receber a imagem que está na Action (Action -> TActionList -> Images(TImageList) ). Bom, até aí tudo bem, o meu problema é que quando mudo a propriedade ´Action.ImageIndex´, não consigo atualizar automaticamente a imagem do TImage.
Como faço para saber quando as propriedades da Action foram trocadas?
Obs.: atribuo a imagem da Action para o TImage no evento ´Paint´ do meu componente, mas ele não executa o ´Paint´ a todo momento.
Utilizo o Delphi 2007.
Lehapan
Curtidas 0
Respostas
Onjahyr
19/03/2009
Aqui neste link ensina como fazer:
[url]http://imasters.uol.com.br/artigo/341/delphi/criando_componentes_no_delphi_-_final/[/url]
[url]http://imasters.uol.com.br/artigo/341/delphi/criando_componentes_no_delphi_-_final/[/url]
GOSTEI 0
Lehapan
19/03/2009
o link não me ajudou...o código do componente segue abaixo:
vincule uma action a este componente, e em tempo de execução, troque a propriedade ImageIndex da Action vínculada a este componente. Aí está o problema, ele não atualiza a imagem.
TBotaoLEH = class(TCustomPanel)
private
FAction: TAction;
FimgAcao: TImage;
FImageIndex: integer;
procedure SetAction(Value: TAction);
procedure AtlzDadosReferenteAction;
protected
protected
procedure Paint; override;
procedure CopiarImagem(imgltAction: TCustomImageList; Indice: Integer);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Action: TAction read FAction write SetAction;
property Align;
property Anchors;
property TabOrder;
property TabStop;
end;
constructor TBotaoLEH.Create(AOwner: TComponent);
begin
inherited Create( AOwner );
FAction := nil;
FImageIndex := -2;
AutoSize := False;
BevelOuter := bvNone;
Height := 18;
Width := 60;
TabStop := True;
Visible := False;
{ FimgAcao }
FimgAcao := TImage.Create( Self );
FimgAcao.Parent := Self;
FimgAcao.AutoSize := False;
FimgAcao.Transparent := True;
FimgAcao.Height := 16;
FimgAcao.Width := 16;
FimgAcao.Left := 4;
FimgAcao.Visible := True;
FimgAcao.ShowHint := True;
end;
destructor TBotaoLEH.Destroy;
begin
FimgAcao.Destroy;
inherited Destroy;
end;
procedure TBotaoLEH.SetAction(Value: TAction);
begin
if FAction <> Value then
begin
FAction := Value;
AtlzDadosReferenteAction;
Repaint;
end
;
end;
procedure TBotaoLEH.AtlzDadosReferenteAction;
begin
Self.Action := FAction;
FImageIndex := -2;
if FAction <> nil then
begin
Self.Enabled := FAction.Enabled;
Self.Visible := FAction.Visible;
end
else
begin
Self.Enabled := False;
Self.Visible := False;
end
;
end;
procedure TBotaoLEH.Paint;
begin
inherited Paint;
if FAction <> nil then
begin
Self.Enabled := FAction.Enabled;
Self.Visible := FAction.Visible;
end
;
{ fImgAcao }
if FimgAcao <> nil then
begin
if ( FAction <> nil ) and ( FAction is TCustomAction ) then
begin
with TCustomAction(FAction) do
begin
{ Copia a imagem da action - Wilson 17/03/2009 }
if FImageIndex <> FAction.ImageIndex then
begin
FImageIndex := FAction.ImageIndex;
if ( ActionList <> nil ) and ( ActionList.Images <> nil )
and ( FImageIndex >= 0 ) and ( FImageIndex < ActionList.Images.Count ) then
CopiarImagem( ActionList.Images, FImageIndex )
else
FimgAcao.Picture := nil
;
end
;
end;
end
;
try
iTop := Trunc( (Self.Height - FimgAcao.Height) div 2 );
if iTop <> FimgAcao.Top then
FimgAcao.Top := iTop
;
except
FimgAcao.Top := 1;
end;
end
;
end;
procedure TBotaoLEH.CopiarImagem(imgltAction: TCustomImageList; Indice: Integer);
begin
with FimgAcao do
begin
Width := imgltAction.Width;
Height := imgltAction.Height;
Picture.Bitmap.Canvas.Brush.Color := clFuchsia;
Picture.Bitmap.Canvas.FillRect( Rect(0, 0, Width, Height) );
imgltAction.GetBitmap( Indice, Picture.Bitmap );
end;
end;
vincule uma action a este componente, e em tempo de execução, troque a propriedade ImageIndex da Action vínculada a este componente. Aí está o problema, ele não atualiza a imagem.
GOSTEI 0