gpt4 book ai didi

delphi - SmartTabs 运行时事件错误

转载 作者:行者123 更新时间:2023-12-03 15:30:57 26 4
gpt4 key购买 nike

这是我收到错误的代码部分:

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;

然后,导航到 TOnTabClos​​eEvent 声明,您会发现:

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;

现在,您可以成功将此方法分配给事件。

关于delphi - SmartTabs 运行时事件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14167864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com