TGraphicControl - detectar modificacoes em subprop |
Top Previous Next |
|
============== DETECTAR MODIFICACOES EM SUBPROPRIEDADES ================
Digamos que temos um componente descendente do TGraphicControl e temos propriedades Brush, e Pen. E quando o usuário modificar estas seja necessario um repaint, como detectar que modificou-se o Pen ou Brush?
Veja exemplo:
private fPen: TPen; fBrush: TBrush;
procedure SetPen (Value: TPen); procedure SetBrush (Value: TBrush); procedure RepaintRequest (Sender: TObject);
public
constructor Create (AOwner: TComponent); override; destructor Destroy; override;
published
property Pen: TPen read fPen write SetPen; property Brush: TBrush read fBrush write SetBrush;
constructor TMdArrow.Create (AOwner: TComponent); begin // chama o construtor pai inherited Create (AOwner);
// define os valores padrões Width := 50; Height := 20;
// criar a pena e o pincel fPen := TPen.Create; fBrush := TBrush.Create;
// define um tratamento para o evento OnChange (AQUI ESTÁ O SEGREDO!!) fPen.OnChange := RepaintRequest; fBrush.OnChange := RepaintRequest; end;
destructor TMdArrow.Destroy; begin // exclui os dois objetos fPen.Free; fBrush.Free; // chama o destruidor pai inherited Destroy; end;
procedure TMdArrow.SetPen (Value: TPen); begin fPen.Assign(Value); Invalidate; <------- Diz para chamar o paint novamente end;
procedure TMdArrow.SetBrush (Value: TBrush); begin fBrush.Assign(Value); Invalidate; <------- Diz para chamar o paint novamente end;
procedure TMdArrow.RepaintRequest (Sender: TObject); begin Invalidate; <------- Diz para chamar o paint novamente end; |