I have created an app for users to create reports in FastReports with charts. The standalone exe works fine. However when I incorporate the same code in a DLL, adding or editing a chart generates the following error:
exception message : Access violation at address 092E95C7 in module 'NEWREPORTDLL.DLL'. Write of address 00000000.
main thread ($5c54):
092e95c7 +007 NEWREPORTDLL.DLL System 18097 +5 TObject.InitInstance
096bcdc4 +010 NEWREPORTDLL.DLL Winapi.GDIPAPI 7277 +1 TGdiplusBase.NewInstance
092e9ba3 +007 NEWREPORTDLL.DLL System 19251 +5 @ClassCreate
096d0df6 +00e NEWREPORTDLL.DLL Winapi.GDIPOBJ 4497 +0 TGPGraphics.Create
09b9088c +010 NEWREPORTDLL.DLL VCLTee.TeeGDIPlus 1274 +1 TGDIPlusCanvas.RecreateGraphics
09b909a8 +048 NEWREPORTDLL.DLL VCLTee.TeeGDIPlus 1305 +6 TGDIPlusCanvas.GetGraphics
09b90dee +0d6 NEWREPORTDLL.DLL VCLTee.TeeGDIPlus 1468 +20 CheckGraphics
09b90ea6 +0ae NEWREPORTDLL.DLL VCLTee.TeeGDIPlus 1504 +31 TGDIPlusCanvas.InitWindow
09af5050 +0a8 NEWREPORTDLL.DLL VCLTee.TeeProcs 2243 +12 InnerDraw
09af517c +010 NEWREPORTDLL.DLL VCLTee.TeeProcs 2279 +7 TCustomTeePanel.Draw
09af64f6 +0ae NEWREPORTDLL.DLL VCLTee.TeeProcs 3322 +19 TCustomTeePanel.NonBufferDraw
09af61c9 +02d NEWREPORTDLL.DLL VCLTee.TeeProcs 3209 +3 TCustomTeePanel.DrawToMetaCanvas
09ba996f +1a3 NEWREPORTDLL.DLL frxChart 1032 +26 TfrxChartView.Draw
0978e70c +044 NEWREPORTDLL.DLL frxClass 12836 +2 TfrxReportComponent.InteractiveDraw
Attempting to add a series results in this:
exception message : Access violation at address 092E95C7 in module 'NEWREPORTDLL.DLL'. Write of address 00000000.
main thread ($5c54):
092e95c7 +007 NEWREPORTDLL.DLL System 18097 +5 TObject.InitInstance
096bcdc4 +010 NEWREPORTDLL.DLL Winapi.GDIPAPI 7277 +1 TGdiplusBase.NewInstance
092e9ba3 +007 NEWREPORTDLL.DLL System 19251 +5 @ClassCreate
096d3c88 +010 NEWREPORTDLL.DLL Winapi.GDIPOBJ 6665 +0 TGPFont.Create
09b91f62 +23a NEWREPORTDLL.DLL VCLTee.TeeGDIPlus 2020 +53 TGDIPlusCanvas.DoChangedFont
09ad1958 +070 NEWREPORTDLL.DLL VCLTee.TeCanvas 5547 +19 TTeeCanvas.AssignFontSize
09ad198c +018 NEWREPORTDLL.DLL VCLTee.TeCanvas 5552 +1 TTeeCanvas.AssignFont
09af54c9 +025 NEWREPORTDLL.DLL VCLTee.TeeProcs 2616 +4 TCustomTeePanel.TryAssignFont
09b99697 +07b NEWREPORTDLL.DLL VCLTee.TeeGalleryPanel 695 +8 TGalleryChart.SetTitleFontSize
DLL Project source is this:
library NewReportDLL;
uses
ShareMem,
System.SysUtils,
System.Classes,
Winapi.Windows,
Winapi.Messages,
System.Variants,
System.IOUtils,
Vcl.Graphics,
VCL.Themes,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
uGlobals in 'uGlobals.pas',
uDMRPT in 'uDMRPT.pas' {DMRPT: TDataModule},
ufrmRptTest in 'ufrmRptTest.pas' {frmReport};
{$R *.res}
function RunReport( cmd: PAnsiChar ):integer;
var
frmReport: TfrmReport;
begin
Application.CreateForm(TDMRPT, DMRPT); // create datamodule
Application.CreateForm(TfrmReport, frmReport); // create form
try
frmReport.ShowModal;
finally
freeandnil(frmReport);
freeandnil( DMRpt );
end;
end;
Exports
RunReport name 'RunReport';
end.
Environment:
Delphi 11.1 FastReports 2023.1.3 Standard Delphi 11.1 TeeChart version included with Delphi
I atempted to install the Steema TeeChart VCL/FMX v2023 Standard to see if it resolved the issue. It fails to install on 11.1.
Any suggestions as to how to eliminate the error would be appreciated.
It might be a problem related to using Microsoft GDI+ inside a dll.
You might want to try the following in the caller exe: https://steema.com/wp/blog/2014/03/12/teechart-and-gdi-inside-a-dll/
or, disabling GDI+ inside the dll, before the charts are created:
TeeDefaultCanvas:='';
regards ! david