Can someone help me with xe7 and rtti?

Can someone help me with xe7 and rtti?

I need to know the tClassType of a not created Object i.e.

var
  myObject:tMyComponent;
begin
  // myObject is only declared but not created at this time
  TestFunction(myObject);
end;

As you can see, the myObject is not created at that moment, but in the TestFunction i need to know the ClassType of the given Object to call its constructor via RTTI ...

procedure TestFunction(vObject:tObject);
var
    ctx : TRttiContext;
    rt : TRttiType;
begin
    ctx := TRttiContext.Create();
    rt := ctx.GetType( vObject); << problem here because vObject was not created ..
......
-snip -

end;

Thanks a lot for some help ...

Comments

  1. What you don't seem to grasp is that until you have an instance, you cannot ask what type that instance is.

    ReplyDelete
  2. Yusuf Zorlu  If you go down the path that Simon Stuart suggests, you can get the information without having an instance, but it may be that for multiple class hierarchies without a common root - Generics will be less work.

    ReplyDelete
  3. Lars Fosdal Simon Stuart Thanks a lot for your introductions / help. Will post here if i have found a working solution. Nice "programmings" ...

    ReplyDelete

Post a Comment