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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - ActiveX Library in Lazarus always freezes
  FAQ FAQ  Forum Search   Register Register  Login Login

ActiveX Library in Lazarus always freezes

 Post Reply Post Reply
Author
Message
RedOctober2018 View Drop Down
Team Player
Team Player
Avatar

Joined: 22 Jun 18
Location: West
Status: Offline
Points: 25
Post Options Post Options   Thanks (0) Thanks(0)   Quote RedOctober2018 Quote  Post ReplyReply Direct Link To This Post Topic: ActiveX Library in Lazarus always freezes
    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;

Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 14 May 19 at 9:34PM
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

Back to Top
RedOctober2018 View Drop Down
Team Player
Team Player
Avatar

Joined: 22 Jun 18
Location: West
Status: Offline
Points: 25
Post Options Post Options   Thanks (0) Thanks(0)   Quote RedOctober2018 Quote  Post ReplyReply Direct Link To This Post Posted: 14 May 19 at 9:43PM
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;

Back to Top
RedOctober2018 View Drop Down
Team Player
Team Player
Avatar

Joined: 22 Jun 18
Location: West
Status: Offline
Points: 25
Post Options Post Options   Thanks (0) Thanks(0)   Quote RedOctober2018 Quote  Post ReplyReply Direct Link To This Post Posted: 14 May 19 at 10:44PM
The problem was caused by my setting the Math.SetRoundMode.

This fixes the file loading problem:

var
...
  rnd_md: TFPURoundingMode;

begin

            rnd_md := Math.GetRoundMode;
            Math.SetRoundMode(rmUp);
            wdti := Round(wdts);
            hgti := Round(hgts);
            Math.SetRoundMode(rnd_md);
          



Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 14 May 19 at 10:49PM
Mmmmh... but you told us that the problem always raise with the second Load...?

Cheers,
Ingo

Back to Top
RedOctober2018 View Drop Down
Team Player
Team Player
Avatar

Joined: 22 Jun 18
Location: West
Status: Offline
Points: 25
Post Options Post Options   Thanks (0) Thanks(0)   Quote RedOctober2018 Quote  Post ReplyReply Direct Link To This Post Posted: 14 May 19 at 11:00PM
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.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store