TeeChart VCL controls use GDI+ (Windows graphics library) by default in VCL applications.
NOTE: The fix indicated below has been already included in the latest VCL version: 2014.11.140512 Download link
There is a “problem” with GDI+ when using it inside a DLL. GDI+ needs to be initialized before using it, and the initialization should be done by the caller EXE process, not by the DLL itself.
(Microsoft information about this can be found here in this link)
This is why the Embarcadero RAD Studio RTL WinApi.GDIPOBJ.pas unit, at the bottom of the file initialization section, checks “if not IsLibrary” to initialize GDI+ only when the unit is used by an executable application.
The problem is, if you have a DLL that contains chart controls, and if GDI+ has not been correctly initialized, an Access Violation exception will be raised from code inside the Windows GDI+ gdiplus.dll !
The solution is quite easy. In your EXE application, before calling any DLL function, add this code to initialize GDI+ :
uses WinAPI.GDIPObj, WinAPI.GDIPApi ;
// Initialize StartupInput structure
StartupInput.DebugEventCallback := nil;
StartupInput.SuppressBackgroundThread := False;
StartupInput.SuppressExternalCodecs := False;
StartupInput.GdiplusVersion := 1;
GdiplusStartup(gdiplusToken, @StartupInput, nil);
It is also recommended (although it doesn’t seem mandatory), to uninitialize GDI+, as one of your EXE last steps:
The next TeeChart release (very soon !) will include a small fix to improve this situation: if GDI+ is not initialized for any reason, it will fallback to “old” GDI graphics instead, avoiding the exception.
Click here to download a simple test project made in Delphi with RAD XE5 that includes an EXE and a DLL. The DLL contains a Form1 with a Chart1. The EXE main unit initializes GDI+ and calls the DLL to show the chart.