I want to use findclass and findcomponent to be able to pass the sender component as parameter in a procedure.
Thank you for reading.
Edit: I use Delphi 2005
[Error]: E2003 Undeclared identifier: 'text'
TestMemo.Text := (FindComponent(VonKomponente.name) as
(Findclass(vonkomponente.ClassType.ClassName))).text; -> does not work
TestMemo.Text := (FindComponent(VonKomponente.name) as TEdit).text; -> works
procedure TFormTest.Edit7DblClick(Sender: TObject);
begin
MemoEdit((Sender as TComponent),'table','row');
end;
procedure TFormTest.MemoEdit(VonKomponente :TComponent;table,row : String);
begin
FormTestMemo.Max_Textlaenge := get_length(table,row);
FormTestMemo.Text := (FindComponent(VonKomponente.name) as
(Findclass(vonkomponente.ClassType.ClassName))).text;
If FormTestMemo.Showmodal = MrOk then
begin
...
end;
end;
What you are trying to do is not possible. You cannot pass a metaclass type determined at runtime to the
as
operator.For what you are trying to do, you will have to resort to using old-style RTTI via the
TypInfo
unit, in this case theTypInfo.GetStrProp()
function, eg:Note that not all text-based components have a
Text
property, some have aCaption
property, eg: