delphi11 type 输出到memo 代码
时间: 2024-01-19 15:02:48 浏览: 27
下面是一个完整的 Delphi 11 示例程序,可以将类型信息输出到 Memo 控件:
```delphi
unit MainForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, TypInfo;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure OutputTypeInfoToMemo(typ: PTypeInfo; memo: TMemo);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
OutputTypeInfoToMemo(TypeInfo(Integer), Memo1);
OutputTypeInfoToMemo(TypeInfo(string), Memo1);
OutputTypeInfoToMemo(TypeInfo(TColor), Memo1);
end;
procedure TForm1.OutputTypeInfoToMemo(typ: PTypeInfo; memo: TMemo);
var
s: string;
begin
s := GetTypeName(typ);
memo.Lines.Add(s);
end;
end.
```
在示例程序中,我们创建了一个名为 `TForm1` 的窗体,其中包含一个 `TMemo` 控件和一个按钮。单击按钮会将三种类型信息输出到 Memo 控件中。在 `OutputTypeInfoToMemo` 过程中,我们使用 `GetTypeName` 函数将类型信息转换为字符串,并将其附加到 Memo 控件的末尾。