Wednesday, September 2, 2009

Dynamically compiling code with Delphi Prism

Delphi Prism and the .NET Framework are both extremely powerful tools and bring a lot of flexibility that Delphi for Win32 cannot necessarily provide, particularly when it comes to reflection and code generation. I recently started a project where I wanted to be able to compile a string with Delphi Prism code into an assembly without hacking my way around with the Delphi Prism command line compiler. This could be used to potentially create a Delphi Prism Snippet Compiler similar to the .NET Snippet Compiler from Jeff Key.

It is my intention that this post should introduce you to the process of dynamically compiling code and that the next part will hopefully be an introduction to the process of dynamically generating and compiling code using the .NET CodeDom.

To begin with, create a New Console Application in Delphi Prism and Add a Reference to the RemObjects.Oxygene.CodeModel assembly. For my installation, this was found in the Bin directory of the Delphi Prism program files directory.

No comments: