像类 TObject、TForm、TComponent。
为什么它们以字母“T”开头?
“T”是什么意思?
最佳答案
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
但是,指针类型、异常类型和接口(interface)类型的常规前缀是
P
, E
, 和 I
, 分别: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;
关于delphi - 为什么 C++ Builder 和 Delphi 类名以字母 T 开头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62446529/