I must be doing something obviously simple and wrong but I can't see it. My platform is: Lazarus 1.8.4 and FPC 3.0.4 QuickPDF, ActiveX, version 10.13.
First Load always works. Second load always freezes. I must be freeing something I shdn't or not freeing something I shd.
What you are looking at is the second attempt where I create and free the QuickPDF object each time. Before I was just using the QuickPDF ActiveX wrapper component. Both methods have exactly the same problem.
function UnlockedQwkPdfOK(const axl: TAxcPDFLibrary): Boolean; begin Result := (axl.OleServer.UnlockKey(quick_pdf_license_key) = 1); end;
function RenderPDFPageAX(const fnm: String; const img: TImage; const sbx: TScrollBox; const sppi, pg: Integer; const zm: Integer; var err_msg: String): Boolean; var axl: TAxcPDFLibrary; vch: Variant; // Variant containing the Canvas Handle bmp: TBitmap; dpi: Integer; wdtd, hgtd, wdtn, hgtn, wdts, hgts: Double; wdti, hgti: Integer; begin Result := True; err_msg := '';
ReleasePdfImg(img);
sbx.HorzScrollBar.Position := 0; sbx.VertScrollBar.Position := 0;
img.AutoSize := True; img.Left := 0; img.Top := 0;
bmp := nil; axl := nil; try axl := TAxcPDFLibrary.Create(nil);
if Assigned(axl) then begin Result := UnlockedQwkPdfOK(axl); if not Result then Exit;
Result := (axl.OleServer.LoadFromFile(fnm, '') = 1); // <--- First time through, file loads and displays correctly. Second time through program freezes at this point. 100% of the time guaranteed freezeup. if Result then begin // Page Points wdtd := axl.OleServer.PageWidth; hgtd := axl.OleServer.PageHeight;
// Page Points to Inches wdtn := wdtd / 72; hgtn := hgtd / 72;
// Inches to Screen pixels wdts := wdtn * sppi; hgts := hgtn * sppi;
Math.SetRoundMode(rmUp); wdti := Round(wdts); hgti := Round(hgts);
dpi := (zm * sppi) div 100;
bmp := TBitmap.Create; bmp.Width := wdti; bmp.Height := hgti; img.Picture.Assign(bmp); vch := bmp.Canvas.Handle; end else begin err_msg := 'Unable to load PDF Viewer from file: ' + fnm + #13 + 'ErrorCode: ' + IntToStr(axl.OleServer.LastErrorCode); Exit; end;
Result := (axl.OleServer.RenderPageToDC(dpi, pg, vch) = 1); if not Result then begin err_msg := 'Unable to render image from QuickPDF ActiveX' + #13 + axl.OleServer.LastRenderError; Exit; end; end; finally axl.Free; bmp.Free; end; end;
procedure ReleasePdfImg(const img: TImage); begin if not Assigned(img) then Exit; img.Picture.Bitmap := nil; img.Picture.Graphic := nil; end;
|