我这样创建了一个TPanel
组件:
procedure TVistaVehiculo.CrearMenu(Name: string);
var
Panel : TPanel;
begin
Panel := TPanel.Create(VistaVehiculo);
Panel.Parent := VistaVehiculo.Sidebar;
Panel.Width := VistaVehiculo.Sidebar.Width;
Panel.Height := 40;
Panel.Caption := Name;
Panel.BevelInner := TBevelCut.bvNone;
Panel.BevelOuter := TBevelCut.bvNone;
Panel.BevelKind := TBevelKind.bkNone;
end;
现在,我想在该面板上附加一个事件侦听器,并将对象作为参数传递。
因此,我创建了一个像这样的过程:
procedure TVistaVehiculo.ClickOnMenu(Sender: TPanel);
begin
Sender.Caption := 'Clicked'; //for example
end;
我该怎么做?
抱歉,问题很愚蠢-我对Delphi还是很陌生
答案 0 :(得分:3)
procedure TVistaVehiculo.CrearMenu(Name: string);
var
Panel : TPanel;
begin
Panel := TPanel.Create(VistaVehiculo);
Panel.Parent := VistaVehiculo.Sidebar;
Panel.Width := VistaVehiculo.Sidebar.Width;
Panel.Height := 40;
Panel.Caption := Name;
Panel.BevelInner := TBevelCut.bvNone;
Panel.BevelOuter := TBevelCut.bvNone;
Panel.BevelKind := TBevelKind.bkNone;
Panel.OnClick := ClickOnMenu; // <-- add this!
end;
procedure TVistaVehiculo.ClickOnMenu(Sender: TObject); // <-- must be TObject!
begin
TPanel(Sender).Caption := 'Clicked';
end;