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.AsClassis wrong since theSQLproperty getter does not return a metaclass type. It returns an object pointer, so useaVal.AsObjectinstead, or evenaVal.AsType<TStrings>.Update If
compis actuallyIOTAComponentthanTValueis definitely wrong to use at all. The output ofIOTAComponent.GetPropValueByName()is an untypedvarthat receives the raw data of the property value, or anIOTAComponentforTPersistent-derived objects:However, a better option would be to access the actual
TADOQueryobject instead: