这是我得到错误的代码的一部分: unit Unit1;interfaceuses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cefvcl, Vcl.ExtCtrls, Vcl.StdCtrls
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cefvcl, Vcl.ExtCtrls, Vcl.StdCtrls, ceflib, Vcl.ComCtrls, Vcl.ImgList, Vcl.Imaging.pngimage, Vcl.Buttons, JvSpeedButton, Themes, JvExComCtrls, JvComCtrls, JvgPage, Vcl.ToolWin, JvToolBar, Vcl.Menus, Vcl.Mask, JvExMask, JvToolEdit, JvExButtons, JvButtons, rkSmartTabs, rkAeroTabs; type TForm1 = class(TForm) {....} procedure FormCreate(Sender: TObject); procedure addnewtab (Sender: TObject); procedure closetab (Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} {....} procedure TForm1.closetab (Sender: TObject); var smarttabs: TrkAeroTabs; begin smarttabs := Sender as TrkAeroTabs; smarttabs.DeleteTab(smarttabs.ActiveTab); end; procedure TForm1.addnewtab (Sender: TObject); var smarttabs: TrkAeroTabs; begin smarttabs := Sender as TrkAeroTabs; smarttabs.AddTab('New Tab'); end; procedure TForm1.FormCreate(Sender: TObject); begin with TrkAeroTabs.Create(self) do begin OnCloseTab := closetab; //***ERROR HERE*** OnAddClick := addnewtab; Parent := Self; Align := alClient; AddTab('New Tab'); if ClassType = TrkAeroTabs then begin ColorBackground := clBlack; with Self do begin GlassFrame.Top := 25; GlassFrame.Enabled := True; end; end; ShowButton := True; AllowTabDrag := True; end; end;
这是错误:
[DCC Error] Unit1.pas(90): E2009 Incompatible types: 'Parameter lists differ'
addnewtab()工作正常.我不明白为什么closetab()不起作用.谢谢.
它不起作用,因为事件是使用与TNotifyEvent不同的类型声明的,并且您的方法参数必须与使用的类型(参数的数量和类型)中声明的内容匹配.导航到事件声明,您会发现:
TrkAeroTabs = class(TCustomControl) .. published .. property OnCloseTab: TOnTabCloseEvent read FOnCloseTab write FOnCloseTab;
然后,导航到TOnTabCloseEvent声明,您会发现:
TOnTabCloseEvent = procedure(Sender: TObject; Index: Integer; var Close: Boolean) of object;
所以,你必须像这样声明你的方法:
TForm1 = class(TForm) .. procedure closetab (Sender: TObject; Index: Integer; var CanClose: Boolean); procedure TForm1.closetab (Sender: TObject; Index: Integer; var CanClose: Boolean); var smarttabs: TrkAeroTabs; begin smarttabs := Sender as TrkAeroTabs; smarttabs.DeleteTab(smarttabs.ActiveTab); end;
现在,您可以成功将此方法分配给事件.