In my Question: How to use “Sender” parameter with “As” operator for more then one class at a time
I choose the Remy Lebeau's Answer because it was the most dynamic tech for most situations like that. It uses the RTTI TypInfo Class.
But as I was using this class, another problem came: How do we Set a sub-property value?
function TRemote.UpdateQuery(DataSet: TDataSet; SQL: String): Boolean;
var
PropInfo: PPropInfo;
begin
{ atualiza o código SQL padrão de um dataSet de consulta tipo View }
PropInfo := GetPropInfo(DataSet, 'SQL', []);
if not Assigned(PropInfo) then
begin
Result := False;
Exit;
end;
try
DataSet.Close;
SetPropValue(DataSet, PropInfo, SQL);
DataSet.Open;
Result := True;
except
Result := False;
end;
end;
Example: I have a TIBQuery and I want to update the text of the SQL property. But the SQL property is a TStrings class, so I have to use SQL.Text. In the code above, It will raise an error "Invalid Property Type" because I got a TStrings and later I try to Set a normal String.
How to reach the SQL.Text using GetPropInfo? Is there a common ancestor of TIBQuery and TZQuery that has the SQL property, so I can change to, instead of the TDataSet in the function parameter?
SQLstrings := TStringList.Create
, then doSQLstrings.Text := SQL
, and finally passSQLstrings
toSetPropValue
? – MorticianSQL
instance you can get simply withTStrings(GetObjectProp(DataSet, 'SQL'))
. Are you sure you need to use theGetPropInfo
? It will be unreadable piece of code. – StruthiousString
instead of byPPropInfo
will raise an exception if the property cannot be found. – AdamokSetObjectProp()
instead.SetPropValue()
does not supports objects. – Adamok