Jump to content

Adding 3rd party controls to uniGUI form


misc

Recommended Posts

Maybe i'm lacking understanding of uniGUI, but I tried to add a THtmlViewer to TuniHiddenPanel, and I always get the message "Cannot assign nil to a font." at runtime. Even when I create it at runtime.

I want to use the THtmlViewer to load some Html and save it as PDF. The Fastreport engine does not create nice tables without having to buy the full product, and IMO it's a little heavy for my task.

 

I want to do something like this:


  HtmlViewer1:= THtmlViewer.Create(Self);
  HtmlViewer1.Parent:= UniHiddenPanel1;  //must have a parent control


    ... load some html code into htm
    HtmlViewer1.LoadTextStrings(htm);  //"cannot assign nil to a font"

    with THtml2Pdf.Create do begin
      Viewer := HtmlViewer1;
      MarginLeft := 10;
      MarginRight := 10;
      ScaleToFit := true;
      Orientation := poLandscape;
      DefaultPaperSize := psA4;
      DrawPageNumber := true;
      DrawPageNumberText := fname + ' - Page %d/%d';
      Execute;
      SaveToFile(fname);
      Free;
    end;

Does anybody have an alternative, or knows how to overcome this?

Link to comment
Share on other sites

I got the THtmlViewer working by placing it on a VCL form and creating it (without showing). Maybe not an intended solution, but no crash so far

 

However, I could not get THtml2Pdf working, because it needs a VCL canvas.

 

The THtmlViewer/THtml2Pdf combination works superb in VCL applications, but I cannot get it to work under uniGUI.

 

So the question that remains: Has anybody found a solution to convert HTML to PDF without the large fingerprint of FastReport and likewise report engines?

Link to comment
Share on other sites

Got the above code to work. I set the Margins too high - they are counted as cm/in, not pixels. I mistook the error message for an uniGUI problem.

 

It's possible to create VCL forms at runtime and put VCL components on it. At least in my case no crashes.

 

So my solution is a free and lean way of converting HTML to PDF.

 

@ Farshad, at this point I must say, you had a truely amazing idea with uniGUI.

Link to comment
Share on other sites

  • Administrators

It's possible to create VCL forms at runtime and put VCL components on it. At least in my case no crashes.

 

Of course you can do this, but when there are many active sessions, trying to access your VCL form and its VCL methods may lead your app into deadlocks or even a crash.

Your method may work for a few session but since it is not thread-safe you can't rely on it. i.e. your app will not be scalable.

Link to comment
Share on other sites

  • 5 months later...

Since I stated using UniGUI I have made my own set of components inheriting from the UniGUi Ones.

 

However today I tried to use my version of TUniEdit and at runtime it gives me "Cannot assign nil to a font."

 

Like what was said in this post.

 

However, I am not using ANY vcl component, just a wapper around it. I am not even changing any properties etc.

 

I have all the other components working like this, based on a wrapper, why is this different?

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...