Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi框架继承的属性不存在_Delphi_Firemonkey - Fatal编程技术网

Delphi框架继承的属性不存在

Delphi框架继承的属性不存在,delphi,firemonkey,Delphi,Firemonkey,在Firemonkey Delphi 10.3中,我创建了一个自定义的TFrame类型来添加功能性: TCustomFrame = class(TFrame); TFrameObserver = class(TCustomFrame, IObserver) public procedure Update; virtual; end; 然后我的框架继承自这个类: TfStore = class(TFrameObserver) 一切都很好,我保存了它,今天早上在设计

在Firemonkey Delphi 10.3中,我创建了一个自定义的TFrame类型来添加功能性:

  TCustomFrame = class(TFrame);

  TFrameObserver = class(TCustomFrame, IObserver)
  public
    procedure Update; virtual;
  end;
然后我的框架继承自这个类:

  TfStore = class(TFrameObserver)
一切都很好,我保存了它,今天早上在设计时打开时出现了错误消息(在执行时也是如此):

属性fStore.Size.Width不存在

当我忽略这些错误时,我看到在.fmx中,它删除了以下属性:

Size.Width
Size.Height
Size.PlateformDefault
并加上:

ClientWidth
ClientHeight
如果我这样做,那就是工作:

TfStore = class(TFrame, IObserver)
我做错什么了吗

复制:

  • 创建一个新的Firemonkey项目

  • 添加从以下测试继承的TFrame:

    类型 IFrameTest=接口 程序测试; 结束; TFrameTest=类(TFrame)

关闭并打开项目以显示错误

以下是我的项目中的代码:

unit Unit2;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls;

type
  IFrameTest = interface
    procedure Test;
  end;

  TFrameTest = class(TFrame);

  TFrameITest = class(TFrameTest, IFrameTest)
    procedure Test; virtual;
  end;

  TFrame2 = class(TFrameITest)
  private
    { Déclarations privées }
  public
    procedure Test; override;
  end;

implementation

{$R *.fmx}

{ TFrameITest }

procedure TFrameITest.Test;
begin
  //
end;

{ TFrame2 }

procedure TFrame2.Test;
begin
  inherited;
  //
end;

end.
以及相应的FMX文件:

object Frame2: TFrame2
  Size.Width = 320.000000000000000000
  Size.Height = 240.000000000000000000
  Size.PlatformDefault = False
end
object Frame3: TFrame3
  Size.Width = 320.000000000000000000
  Size.Height = 240.000000000000000000
  Size.PlatformDefault = False
end

TFrame是一个类,IDE为其执行特殊的魔法

要从另一个框架继承框架,请首先使用IDE创建框架,然后使用IDE创建继承的框架(菜单文件/New/other…/Inheritable items/选择第一个框架)

我知道你需要一个接口。在第一个(祖先)框架中定义它,并将其添加到类声明中

当您拥有继承的框架时,您可以(不是强制的,取决于您想要做什么)重写实现接口的虚拟方法

以下是具有接口的基本帧(TFrame3)的代码:

unit Unit3;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls;

type
  IFrameTest = interface
    procedure Test;
  end;

  TFrame3 = class(TFrame)
  private
    { Private declarations }
  public
    procedure Test; virtual;
  end;

implementation

{$R *.fmx}

{ TFrame3 }

procedure TFrame3.Test;
begin
    ShowMessage('TFrame3.Test');
end;

end.
以及相应的FMX文件:

object Frame2: TFrame2
  Size.Width = 320.000000000000000000
  Size.Height = 240.000000000000000000
  Size.PlatformDefault = False
end
object Frame3: TFrame3
  Size.Width = 320.000000000000000000
  Size.Height = 240.000000000000000000
  Size.PlatformDefault = False
end
下面是继承帧(TFrame4)的代码:

以及相应的FMX:

inherited Frame4: TFrame4
  Size.Width = 455.000000000000000000
  Size.Height = 337.000000000000000000
end

您是否可以编辑您的问题并添加一个简单的小示例程序来再现您看到的行为?发布pas和fmx文件。我在github中添加代码并编辑questionPlease@Boss Stack Overflow,要求在问题帖子中包含再现问题的所有代码和其他信息。Ref::标题“完成”下写着:确保重现问题所需的所有信息都包含在问题本身中。指向外部站点的链接不符合条件。感谢您对我的问题的帮助。。您必须复制所有内容,github源代码可以帮助修复此解决方案的问题,您不认为这是一个Delphi问题吗?我需要开一张去Embarcadero的票吗?不,这不是德尔福的问题。如果希望IDE能够管理您的帧,则必须遵循规则。您编写的代码语法正确,但与IDE工作不兼容。如果不要求IDE管理您的框架,您可以使用它。