【问题标题】:Why does C++ Builder and Delphi class names begin with the letter T?为什么 C++ Builder 和 Delphi 类名以字母 T 开头?
【发布时间】:2020-06-18 09:16:13
【问题描述】:

类似于 TObject、TForm、TComponent 类。

为什么它们以字母“T”开头?

“T”是什么意思?

【问题讨论】:

  • 您能否提供一个代码示例来阐明您的意思?
  • 这是 Borland 使用的 Hungarian notation(最初开发这些产品)。就是这样。当时这种表示法很流行,现在当IDE能力得到很大改进时,这种表示法被认为已经过时了。

标签: delphi c++builder


【解决方案1】:

T 代表“类型”,它通常用作非内置类型的常规前缀,而不仅仅是类类型:

type
  TFileName = type string; // string
  TErrorCode = 1..100; // subrange type
  TCarSize = (csSmall, csMedium, csLarge); // enumeration
  TCarSizes = set of TCarSize; // set
  TPersonRec = record // record
    FirstName: string;
    LastName: string;
    Age: Integer;
  end;
  TSuperBitmap = class(TBitmap) // class
    {...}
  end;
  TDeviceData = array[0..1023] of Byte; // static array
  TLogProc = procedure(const AMessage: string; AKind: TLogKind); // procedural type
  // and so on

但是,指针类型、异常类型和接口类型的常规前缀分别是PEI

type
  PPersonRec = ^TPersonRec;
  ESyntaxError = class(EScriptException);
  ISoundPlayer = interface
    {...}
  end;

还有其他几种约定,例如字段的F

type
  TCar = class
  strict private
    FModel: string;
    FColor: TColor;
    FWeight: Double;
  end;

A 用于参数:

procedure MyShowMessage(const AMessage: string; AIconType: TIconType);

有时人们使用L 表示局部变量:

procedure MyShowMessage(const AMessage: string; AIconType: TIconType);
var
  LCaption: string;
  LIcon: HICON;
begin

end;

【讨论】:

  • 但不是 TString 或 TInteger :-)
  • 这些也应该适合您的列表:I 用于接口,Co 用于 COM 类工厂。
  • 有趣的事实:Stack Overflow 上的一些用户对 delphi 标签感兴趣,在他们的昵称中使用 T 前缀。 @OndrejKelle a.k.a. TOndrej, @TLama.
  • @PeterWolf:E 用于异常类型,P 用于指针类型。我已经添加了这些。还有 S 用于字符串常量和资源字符串。
  • @JerryDodge G 也常用于全局变量。 C 用于常量
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-26
  • 2018-03-27
  • 2010-09-25
  • 2017-10-28
  • 2011-01-18
  • 1970-01-01
相关资源
最近更新 更多