Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



This topic is 6356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello there, in VB there is a function called CallByName which you can simply pass the name of an object the method to be called and the parameters to be passed is there anything simular in Delphi.(Before I write my own). Thank you.

Share this post

Link to post
Share on other sites
It can certainly be done, but it is not as simple as it first seems. Firstly, not all objects have a Name property. They must descend from TComponent to get the Name property or specify a Name property for each object.

Secondly, this would be a real time killer in an application, especially if it was called inside a tight loop. This is why:
  • Iterate through all known objects
    • retrieving the RTTI for the object
    • iterating through published properties to find the Name property
    • doing a string compare with the Name property
    until a match is found.
  • Iterate through all public methods of the object doing a string compare until the given method name is found.
  • Call the method.
As you can see, this would be awfully slow in an application that potentially had hundreds or thousands of objects.

Steve ''Sly'' Williams  Code Monkey  Krome Studios

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!