Delphi Frame继承的属性不存在

标签 delphi firemonkey tframe

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

  TCustomFrame = class(TFrame);

  TFrameObserver = class(TCustomFrame, IObserver)
  public
    procedure Update; virtual;
  end;

然后我的框架继承自这个类:

  TfStore = class(TFrameObserver)

一切都很好,我保存了它,今天早上在设计时打开时出现错误消息(与执行时相同):

Property fStore.Size.Width does not exist

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

Size.Width
Size.Height
Size.PlateformDefault

并添加:

ClientWidth
ClientHeight

如果我这样做,那就成功了:

TfStore = class(TFrame, IObserver)

我做错了什么吗?

重现:

  • 创建一个新的 Firemonkey 项目

  • 添加一个从下面的测试继承的 TFrame:

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

    TFrameITest = class(TFrameTest, IFrameTest)
      procedure Test; virtual;
    end;
    
    TFrame1 = class(TFrameITest)
    private
      { Déclarations privées }
    public
      procedure Test; override;
    end;
    

关闭并打开项目出现错误

这是我的项目的代码:

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

最佳答案

TFrame 是一个由 IDE 施展特殊魔法的类。

要从另一个框架继承框架,请首先使用 IDE 创建框架,然后使用 IDE 创建继承的框架(菜单文件/新建/其他.../可继承项目/选择第一个框架)。

我发现您需要一个界面。在第一个(祖先)框架中定义它并将其添加到类声明中。

当您拥有继承的框架时,您可以(不是强制的,取决于您想要执行的操作)重写实现接口(interface)的虚拟方法。

这里是具有接口(interface)的基础框架(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 Frame3: TFrame3
  Size.Width = 320.000000000000000000
  Size.Height = 240.000000000000000000
  Size.PlatformDefault = False
end

这里是继承框架(TFrame4)的代码:

unit Unit4;

interface

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

type
  TFrame4 = class(TFrame3)
  private
    { Private declarations }
  public
    procedure Test; override;
  end;

var
  Frame4: TFrame4;

implementation

{$R *.fmx}

{ TFrame4 }

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

end.

以及对应的FMX:

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

关于Delphi Frame继承的属性不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65195728/

相关文章:

android - 在 Android 上使用 TPopup 代替 showmessage

delphi - 将Tframe从bpl加载到应用程序

delphi - 为什么“Bitmap.SaveToFile”导致黑屏

.net - 代码页 ID 到代码页名称 : GetEncoding equivalent in Delphi?

windows - 如何创建一个监听windows事件的应用程序?

delphi - 使用 Firemonkey 和 Delphi XE2 进行数据库查找字段

delphi - FireMonkey - 在 Windows 中绘制 1 像素线而不进行抗锯齿

delphi - 在运行时创建 Tframe :

delphi - TFrame 内的事件处理程序?

delphi - 如何自定义滚动条颜色?