I'm implementing a package to convert and auto-generate components in the delphi IDE. I'm aware that GExperts has a similar function but I need to customize some specific properties.
Right now I'm stuck on accessing the TADOQuery.SQL
property, which is an instance of TStrings:
var
aVal : TValue;
aSqlS : TStrings;
begin
[...]
if (mycomp.GetComponentType = 'TADOQuery') then
if mycomp.GetPropValueByName('SQL', aVal) then
begin
aSqlS := TStrings(aVal.AsClass);
if Assigned(aSqlS) then <----- problem is here
ShowMessage(aSqlS.Text); <----- problem is here
end;
end;
I'm not really sure whether using TValue from RTTI is the correct way to go.
Thanks
Assuming
GetPropValueByName()
is returning a validTValue
(you did not show that code), then usingaVal.AsClass
is wrong since theSQL
property getter does not return a metaclass type. It returns an object pointer, so useaVal.AsObject
instead, or evenaVal.AsType<TStrings>
.Update If
comp
is actuallyIOTAComponent
thanTValue
is definitely wrong to use at all. The output ofIOTAComponent.GetPropValueByName()
is an untypedvar
that receives the raw data of the property value, or anIOTAComponent
forTPersistent
-derived objects:However, a better option would be to access the actual
TADOQuery
object instead: