I am trying to use extented RTTI features This is where i stuck.
t := (c.FindType('Classes.TStringList') as TRttiInstanceType);
SL := t.GetMethod('Create').Invoke(t.MetaclassType,[]);
t.GetMethod('Add').Invoke(SL,['Hello Do you like my hat?']);
Lines := t.GetProperty('Text').GetValue(SL.AsObject);
Untill now it works fine
Now i want to alter the value
Lines := 'Test';
t.GetProperty('Text').SetValue(**?**,Lines);
What should i give here the TRTTIinstancetype reference or the actual object reference.
If Actual Object reference how will i give that.
TestStringList := t(**how will i get the actual object from this TRTTIinstancetype**).
The
Instanceparameter ofSetValueis exactly the same as theInstanceparameter ofGetValue. So you simply need to pass exactly what already did when you calledGetValue. NamelySL.AsObject:Regarding the very final part of your question, if you ever need to convert
SLinto an object with a specific class,TStringListin this case then you can use a runtime cast:However, doing that rather implies that you don’t need to be using RTTI in the first place. Using the method in the first part of my answer is the RTTI way to do what you ask.