an example, I need to do this to solve a problem in a framework I am developing :
//Unit2 :
procedure A(aForm : TForm; AClassType: TFormClass);
begin
ShowMessage (AClassType(aForm).edtUser.text);
end;
...
//Unit1 :
Uses Unit2;
begin
form1 := TForm1.Create;
Try
A(form1, TForm1);
Finally
form1.Free;
End;
end;
The compiler does not accept this line:
AClassType (aform).edtUser.text
One solution would be to use:
Uses
UnitofTForm1;
The procedure (aform: TForm; AClassType: TForm1);
begin
ShowMessage (AClassType (aform).edtUser.text);
end;
But I can not do so because they are giving circular reference and I need some decoupling in my framework
Is there any way to make typecast passing as parameter the type of form or is there another way to do this ?
What you are asking for can be done by either:
deriving the various Form classes from a common base class that exposes the field you want to access:
or, use Generics:
if a common base class is not possible, use an interface instead:
or, use legacy RTTI (only works with published properties):
or, use extended RTTI (works with all fields and visibility):