If I override the click method of a TButton, when the control is clicked, the code of that method is executed, as I expect:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TButton }
TButton=class(StdCtrls.TButton)
procedure Click; override;
end;
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
Button : TButton;
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TButton }
procedure TButton.Click;
begin
inherited Click;
writeln('Click');
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Button:=TButton.Create(self);
Button.Parent:=self;
end;
end.
If I override the click method of a TTreeView, when the control is clicked, the code of that method is not executed:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls;
type
{ TreeView }
TreeView=class(ComCtrls.TTreeView)
protected
procedure Click; override;
end;
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
TreeView : TTreeView;
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TreeView }
procedure TreeView.Click;
begin
inherited;
writeln('TreeView.Click');
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
TreeNode : TTreeNode;
begin
TreeView:=TTreeView.Create(self);
TreeView.Parent:=self;
TreeView.Align:=alClient;
TreeNode:=TTreeNode.Create(TreeView.Items);
TreeView.Items.Add(TreeNode,'ok1');
TreeNode:=TTreeNode.Create(TreeView.Items);
TreeView.Items.Add(TreeNode,'ok2');
end;
end.
What is the reason for this different behavior? Thanks.