How It Works
In Button1's OnClick event handler, LoadLibrary() is called to load CALDLL. If it fails to load, an exception is raised. If the call is successful, a call to the window's GetProcAddress() is made to get the address of the function ShowCalendar(). Prepending the procedural datatype variable ShowCalendar with the address of operator (@) character prevents the compiler from issuing a type mismatch error due to its strict type-checking. After obtaining the address of ShowCalendar(), you can use it as defined by TShowCalendar. Finally, FreeLibrary() is called within the finally block to ensure that the library is freed from memory when no longer required.
You can see that the library is loaded and freed each time this function is called. If this function was called only once during the run of an application, it becomes apparent how explicit loading can save much-needed and often limited memory resources. On the other hand, if this function were called frequently, the DLL loading and unloading would add a lot of overhead.