1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75:
| unit Unit2; interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,TypINfo,rtti;
type TDataClass = class FKID: Integer; FName: string; FVorname: string; FADRID: integer; published Property KID: Integer read FKID write FKID; Property Name: string read FName write FName; Property Vorname: string read FVorname write FVorname; Property ADRID: Integer read FADRID write FADRID; end; TForm2 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private public d:TDataClass; end;
var Form2: TForm2;
implementation
{$R *.dfm}
Procedure SetValue(obj:TObject;aName:String;AValue:Variant); var PropInfos: TPropList; PropTypeName : string; pi : PPropInfo; i:Integer; begin for i := 0 to GetPropList(obj.ClassInfo, tkProperties, @PropInfos) - 1 do begin if PropInfos[i].Name = aName then begin case PropType(obj , PropInfos[i].Name) of tkInteger: SetOrdProp(obj , PropInfos[i].Name, AValue); tkFloat: SetFloatProp(obj , PropInfos[i].Name, AValue); tkString, tkLString,tkUString: SetStrProp(obj , PropInfos[i].Name, AValue); end; end;
end; end;
procedure TForm2.Button1Click(Sender: TObject); var d:TDataClass; begin d:=TDataClass.Create; SetValue(d,'Name','Test'); SetValue(d,'KID',1234); Showmessage(d.Name + #13#10 + IntToStr(d.KID) ); d.Free; end;
end. |