Loading Packages with the LoadPackage Function
Go Up to Loading Packages in an Application
You can also load a package at run time by calling the System.SysUtils.LoadPackage function. LoadPackage loads the package specified by its name parameter, checks for duplicate units, and calls the initialization blocks of all units contained in the package. For example, the following code could be executed when a file is chosen in a file-selection dialog.
with OpenDialog1 do if Execute then with PackageList.Items do AddObject(FileName, Pointer(LoadPackage(FileName)));
if (OpenDialog1->Execute()) PackageList->Items->AddObject(OpenDialog1->FileName, (TObject *)LoadPackage(OpenDialog1->FileName));
To unload a package dynamically, call UnloadPackage. Be careful to destroy any instances of classes defined in the package and to unregister classes that were registered by it.