Delphi Dynamic method invocation [closed]-Collection of common programming errors

“Invoke methods dynamically” can mean a number of different things. Simple late-binding is built into the language in the form of methods declared as virtual or dynamic, and you probably use them all the time, particularly the virtual ones.

But talking about “invoking methods dynamically” generally gets into scripting territory, making it possible to take an object and let the end-user decide, at runtime, which method to call by using the method’s name. If you want that, you need a scripting library for Delphi.

DWS (Delphi Web Script) works quite well, and the author claims that it supports D2009, though active development work takes place on XE. Also, as the name implies, DWS is designed primarily with web development in mind, and so the framework for binding scripts to objects in native code-land is a lot more complicated than it probably should be.

The other major alternative is RemObjects’s PascalScript library. It supports earlier versions than D2009, and its system for object binding is a lot simpler than DWS’s. Unfortunately, it’s also much slower and not well supported by the author. But, especially for simple scripts, either one should make you able to allow users to dynamically automate stuff in your program.