delphi - Assigning properties using RTTI without knowing what type the property is -


i have object newobject unknown properties , want able assign values properties without knowing type property is.

the best can far

vctx := trtticontext.create; vtype := vctx.gettype(newobject.classtype);  vprop in vtype.getproperties begin         vpropvalue := 'test value';      val := tvalue.from<string>( vpropvalue);      vprop.setvalue( newobject , val ); end; 

of course, assumes properties of type string

how make more general?

since don't provide information of value , can handle (in comments) post part find out property type , leave rest unless provide additional information.

i leave other type kinds , give rough idea.

if vprop.iswritable begin   case vprop.propertytype.typekind of     tkinteger: val := tvalue.from<integer>(...);     tkfloat:   val := tvalue.from<double>(...);     tkustring: val := tvalue.from<string>(...);   end;   vprop.setvalue(newobject, val); end; 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -