Edgar Pavão
Edgar Pavão

Reputation: 49

Is there any way to load a unit dynamically in Delphi?

When an application is already running (runtime), is it possible to dynamically load a .pas file and use it?

Upvotes: 1

Views: 1261

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 597051

Not directly, no.

A .pas file must be compiled into a .dcu file and linked into an executable (program or library) before it can then be executed at runtime.

If you need to load and execute the code dynamically, you can compile the unit into a runtime Package (bpl) first, and then load that file at runtime using the LoadPackage() function. See the following articles for more details:

Loading Packages in an Application

Loading Packages with the LoadPackage Function

Dynamic packages in Delphi

How to dynamically load and call a function in a BPL package

Upvotes: 6

David Heffernan
David Heffernan

Reputation: 613262

The simple answer to your question is no. Pascal is source code and cannot be executed directly. It must first be translated one way or another.

Upvotes: 0

Related Questions