【问题标题】:Delphi-FireMonkey-Undeclared Identifier 'TEdit' ;Undeclared Identifier 'TLabel';Delphi-FireMonkey-未声明的标识符'TEdit';未声明的标识符'TLabel';
【发布时间】:2014-03-05 01:36:58
【问题描述】:

我正在 Firemonkey-RAD Studio XE3-Delphi 中开发一个练习应用程序。 实现代码时出现以下错误:

未声明的标识符“TEdit” 未声明的标识符“TLabel” 'TLabel' 在第 35 行不包含名为 'caption' 的成员

我将项目的代码包含在以下正文中。

感谢任何帮助。对我放轻松..我是 Delphi 的新手。

 unit strcode1u1;

    interface

    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

    type
      Tstrcode1f1 = class(TForm)
        ePlainText: TEdit;
        laEncrypted: TLabel;
        procedure ePlainTextChange(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      strcode1f1: Tstrcode1f1;

    implementation

    {$R *.dfm}

    procedure Tstrcode1f1.ePlainTextChange(Sender: TObject);
    begin

    end;

    procedure Tstrcode1f1.FormCreate(Sender: TObject);
    begin
    laEncrypted.caption:=
        chr(72)+chr(101)+chr(108)+
        chr(108)+chr(111)+chr(32)+
        chr(87)+chr(111)+chr(114)+
        chr(108)+chr(100);
    end;
    end.

【问题讨论】:

  • 我确定您的问题已经得到解答。请根据您的判断接受最佳答案。
  • @David 这种行为没有术语吗?我能想到的最好的就是吃饭和冲刺......

标签: delphi


【解决方案1】:

您说您正在创建一个 FireMonkey 应用程序,但您的 uses 子句包含对 VCL 单元的引用:

Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs

代替 FireMonkey 单位:

FMX.Controls, FMX.Forms, FMX.Dialogs

【讨论】:

  • +1。接得好。我错过的另一个问题。 (您可能还想添加 .dfm 而不是 .fmx。)
【解决方案2】:

除了@Remy 的回答之外,还有一个问题。 FireMonkey 中的TLabel 没有标题,正如您在对象检查器中看到的那样。

它(和所有其他 FMX 控件)改为使用 Text

首先创建一个新的 FireMonkey 应用程序(文件->新建->FireMonkey 桌面应用程序 - IDE 主菜单中的 Delphi)。出现下一个对话框时,选择您需要 FireMonkey HD 还是 3D 应用程序(文档可以解释两者之间的区别)。

然后您可以在表单上放置一个 TLabel 和 TEdit,在 Object Inspector 中正确命名它们,然后将您的代码改为:

aEncrypted.Text:= chr(72)+chr(101)+chr(108)+
                  chr(108)+chr(111)+chr(32)+
                  chr(87)+chr(111)+chr(114)+
                  chr(108)+chr(100);

【讨论】: