Consider the following program:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Shape1: TShape;
procedure FormCreate(Sender: TObject);
procedure Shape1ChangeBounds(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Shape1.Left:=Shape1.Left+100;
end;
procedure TForm1.Shape1ChangeBounds(Sender: TObject);
begin
Caption:='ok';
end;
end.
Changing Shape1.Left within OnCreate does not trigger Shape1ChangeBounds.
Differently, changing Shape1.Left within OnShow triggers Shape1ChangeBounds, as in the following program:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Shape1: TShape;
procedure FormShow(Sender: TObject);
procedure Shape1ChangeBounds(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormShow(Sender: TObject);
begin
Shape1.Left:=Shape1.Left+100;
end;
procedure TForm1.Shape1ChangeBounds(Sender: TObject);
begin
Caption:='ok';
end;
end.
Why this different behavior?
I ask because I would need to intercept all changes to the Left and Top properties of a component I'm writing, even those that happen within OnCreate events of the parent control. Left and Top have getters and setters that are not virtual and this prevents me from redefining them in descending control.
Any suggestions? Thanks!