Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
ActiveX Library in Lazarus always freezes |
Post Reply |
Author | |
RedOctober2018
Team Player Joined: 22 Jun 18 Location: West Status: Offline Points: 25 |
Post Options
Thanks(0)
Posted: 14 May 19 at 5:43PM |
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; |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Red and anybody who's reading here,
i always like to help but ActiveX isn't mine - so if there is anybody out there and like to give as well as to take... please advice ;-) |
|
Cheers,
Ingo |
|
RedOctober2018
Team Player Joined: 22 Jun 18 Location: West Status: Offline Points: 25 |
Post Options
Thanks(0)
|
I have rebuilt the function to use a variant, but the exact same problem happens upon file load. This fails in the exact same spot (on file load)
Here is the code: function RenderPDFPageDLL(const fnm: String; const img: TImage; const sbx: TScrollBox; const sppi, pg: Integer; const zm: Integer; var err_msg: String): Boolean; var qwk: Variant; 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; qwk := nil; try qwk := CreateOleObject('DebenuPDFLibraryAX1013.PDFLibrary'); if not VarIsEmpty(qwk) then begin Result := qwk.UnlockKey(quick_pdf_license_key); if not Result then Exit; Result := (qwk.LoadFromFile(fnm, '') = 1); if Result then begin // Page Points wdtd := qwk.PageWidth; hgtd := qwk.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(qwk.LastErrorCode); Exit; end; Result := (qwk.RenderPageToDC(dpi, pg, vch) = 1); if not Result then begin err_msg := 'Unable to render image from QuickPDF ActiveX' + #13 + qwk.LastRenderError; Exit; end; end; finally qwk := null; bmp.Free; end; end; |
|
RedOctober2018
Team Player Joined: 22 Jun 18 Location: West Status: Offline Points: 25 |
Post Options
Thanks(0)
|
The problem was caused by my setting the Math.SetRoundMode.
This fixes the file loading problem: var ... rnd_md: TFPURoundingMode; rnd_md := Math.GetRoundMode; Math.SetRoundMode(rmUp); wdti := Round(wdts); hgti := Round(hgts); Math.SetRoundMode(rnd_md); |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Mmmmh... but you told us that the problem always raise with the second Load...?
|
|
Cheers,
Ingo |
|
RedOctober2018
Team Player Joined: 22 Jun 18 Location: West Status: Offline Points: 25 |
Post Options
Thanks(0)
|
Correct. The line of code that sets the rounding comes after the first file load. So the second file load occurs with the rmUp still in effect.
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store