如果在运行时就给定的一个类得知它分别有哪些属性? 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 去看《Delphi5开发人员指南》一书中RTTI那一章,里面讲解的很详细了 请继续关注这个问题http://expert.csdn.net/Expert/TopicView1.asp?id=1793141谢谢 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type {$M+} TNewRec = class private FA : String; FD : Char; FC : Integer; FB : String; FE : TDateTime; published property A: string read FA write FA; property D: Char read FD write FD; property C: Integer read FC write FC; property B: string read FB write FB; property E: TDateTime read FE write FE; end; {M-} TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementationuses TypInfo;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var PropList: PPropList; PropCount: Integer; I: Integer;begin PropCount := GetPropList(TNewRec.ClassInfo, PropList); for I := 0 to PropCount - 1 do Memo1.Lines.Add('字段名: ' + PropList[I].Name + '====' + '类型: ' + Copy(GetEnumName(TypeInfo(TTypeKind), Integer(PropList[I].PropType^.Kind)), 3 , MaxInt));end;end. 在D5下,这样procedure TForm1.Button1Click(Sender: TObject);var PropList: PPropList; PropCount: Integer; I: Integer;begin PropCount := GetTypeData(TNewRec.ClassInfo)^.PropCount; GetMem(PropList, PropCount * SizeOf(Pointer)); try GetPropInfos(TNewRec.ClassInfo, PropList); for I := 0 to PropCount - 1 do Memo1.Lines.Add('字段名: ' + PropList[I].Name + '====' + '类型: ' + Copy(GetEnumName(TypeInfo(TTypeKind), Integer(PropList[I].PropType^.Kind)), 3 , MaxInt)); finally FreeMem(PropList); end;end; delphi7的treeview的treenode有tag属性吗,没有如何加tag属性? 求高人指点迷津,如何截获TComboBox的下拉列表滚动的消息。 QR 或 FR如何实现竖着打印数据库中的字段? SQL语句问题 达人们请来帮帮我 头痛一天了 怀旧一下 idftp控件中的一个问题 读取DFM窗口内容。 一个技术难题 如何使指定窗体成为当前激活窗体? [调查]由谁用正版的delphi 帮帮忙?? 请问dbcheckbox有没有一个字段是设置默认值的?
http://expert.csdn.net/Expert/TopicView1.asp?id=1793141
谢谢
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
{$M+}
TNewRec = class
private
FA : String;
FD : Char;
FC : Integer;
FB : String;
FE : TDateTime;
published
property A: string read FA write FA;
property D: Char read FD write FD;
property C: Integer read FC write FC;
property B: string read FB write FB;
property E: TDateTime read FE write FE;
end;
{M-} TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
uses TypInfo;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
PropList: PPropList;
PropCount: Integer;
I: Integer;
begin
PropCount := GetPropList(TNewRec.ClassInfo, PropList);
for I := 0 to PropCount - 1 do
Memo1.Lines.Add('字段名: ' + PropList[I].Name + '====' +
'类型: ' +
Copy(GetEnumName(TypeInfo(TTypeKind), Integer(PropList[I].PropType^.Kind)), 3 , MaxInt));
end;end.
var
PropList: PPropList;
PropCount: Integer;
I: Integer;
begin
PropCount := GetTypeData(TNewRec.ClassInfo)^.PropCount;
GetMem(PropList, PropCount * SizeOf(Pointer));
try
GetPropInfos(TNewRec.ClassInfo, PropList);
for I := 0 to PropCount - 1 do
Memo1.Lines.Add('字段名: ' + PropList[I].Name + '====' +
'类型: ' +
Copy(GetEnumName(TypeInfo(TTypeKind), Integer(PropList[I].PropType^.Kind)), 3 , MaxInt));
finally
FreeMem(PropList);
end;
end;