News combit Dev Blog

Designer Preview Support for Xbase++

Posted: Friday, April 24, 2015 | 0 comment(s)
 
Today, I spoke at the Xbase Forum Meeting in Potsdam, Germany. Besides presenting what our reporting tool can do I had the joy and honor to share my presentation with Tom Liehr, a respected member of the Xbase++ community. Together we've created a modified sample for Xbase++ that shows how to support the designer preview in Xbase++. Or – better said – Tom did most of the hard work while I stood flabbergasted at the sideline. I was only able to give some hints that helped crossing the finish line just in time which was Easter Monday, 10:30 pm.

As the sample shows a generic approach how callbacks and threads can be used in Xbase++ I wanted to share the central parts here as well. First of all, two additional 3rd party packages are required, the Binary Access Package for Xbase++ (BAP) that can be downloaded from Alaska Software and the excellent OT4XB. The first is used to support callbacks, the second helps to work with C++ structures. In order to register for a callback, all that's needed is:

 

// Initialize callback function using BAP
nCallBack := BaCallBack("DesignerCallback", BA_CB_GENERIC3)

// Hand callback function handle to LL
LlSetNotificationCallbackExt(hJob,LL_NTFY_DESIGNERPRINTJOB,nCallBack)


DesignerCallback is a function that has a signature like:

 

FUNCTION DesignerCallback(nNotification,nStructurePtr,xUserParam)

 

The tricky part now is working with the structure pointer. The structure that's passed in case of the designer preview can be declared like this using OT4XB:


BEGIN STRUCTURE My_LlCallback
  MEMBER UINT         _nSize
  MEMBER POINTER      _nUserParam
  MEMBER POINTER32    _pszProjectName
  MEMBER POINTER32    _pszOriginalProjectFileName
  MEMBER UINT         _nPages
  MEMBER UINT         _nFunction
  MEMBER HWND         _hWnd
  MEMBER HANDLE       _hEvent
  MEMBER POINTER32    _pszExportFormat
  MEMBER BOOL         _bWithoutDialog
END STRUCTURE

 

And the nSturcturePtr that's received by the DesignerCallback function can then be "marshalled" to the Xbase++ world using:

// Create a local copy of the structure
// get the structure nStructurePtr points to - .F. means: not a copy
oCbLocal   := My_LlCallback():New():_link_(nStructurePtr,.F.) 
oCbLocal:_lock_()
… // do something with oCbLocal
oCbLocal:_unlock_() // unlock the structure
oCbLocal:_unlink_(.F.) // unlink the structure

An important thing to keep in mind is that you need to copy all members of the structure to local/global variables as the structure will no longer be valid once the callback routine returns. So you cannot rely on the validity of any of the structure members anywhere else in the code. Thus, the sample copies all members and passes these copies to the central printing routine:

 

// Init values for the print thread
cProjectName := PeekStr(oCbLocal:_pszProjectName,,-1) // filename from structure pointer
cOrgProjectName := PeekStr(oCbLocal:_pszOriginalProjectFileName,,-1) // filename from structure pointer
nProjecthWnd := oCbLocal:_hWnd // window handle
nRecNo       := oCbLocal:_nUserParam // record number in INVOICE.DBF
nPages       := oCbLocal:_nPages // number of pages to be printed
hEvent       := oCbLocal:_hEvent // event handle for synchronization
// Start print thread
oPrintThread := Thread():new()
oPrintThread:start( {||PrintPreviewData(cProjectName,cOrgProjectName,nProjecthWnd,nRecNo,nPages,hEvent)})

 

The PrintPreviewData routine is more or less identical to the "normal" printing, only the progress box is removed by using LlPrintStart() instead of LlPrintWithBoxStart() and the print code attaches to the designer's preview window by calling LlAssociatePreviewControl(). We'll add the full sample to our knowledge base area shortly.

The sample could easily be extended to support the drilldown callback as well, which would enable the report parameter pane in the preview or expandable regions for Xbase++ applications.

Thanks again to the German Xbase-Forum for inviting me to Potsdam (which gives me an opportunity to spend the weekend there <g>) and of course thanks very much to Tom Liehr who really went the extra mile in order to make this happen.




Author: Jochen Bartlau
Head of Development List & Label

Jochen Bartlau leads the development at combit as Managing Director. He's a Microsoft .NET enthusiast driving innovation & agile project management. The mobile devices geek who used to be a physicist in his first life loves to spend his spare time with his family.


  

RSS
combit Development BlogRSS
What’s this blog for?
A place to share updates about the ongoing development of our products. General musings on the software industry included.
Archive
January 2021 (1)
December 2020 (2)
November 2020 (1)
October 2020 (2)
September 2020 (1)
August 2020 (2)
July 2020 (1)
June 2020 (1)
May 2020 (2)
April 2020 (2)
March 2020 (2)
February 2020 (1)
January 2020 (1)
December 2019 (1)
November 2019 (2)
October 2019 (2)
September 2019 (2)
August 2019 (2)
July 2019 (2)
June 2019 (2)
May 2019 (1)
April 2019 (0)
April 2019 (1)
March 2019 (1)
February 2019 (1)
January 2019 (1)
December 2018 (1)
November 2018 (2)
October 2018 (4)
September 2018 (4)
August 2018 (2)
July 2018 (2)
June 2018 (2)
May 2018 (1)
April 2018 (1)
March 2018 (1)
February 2018 (2)
January 2018 (1)
December 2017 (1)
November 2017 (2)
October 2017 (3)
September 2017 (3)
August 2017 (2)
July 2017 (2)
June 2017 (1)
May 2017 (2)
April 2017 (1)
March 2017 (1)
February 2017 (1)
January 2017 (2)
December 2016 (1)
November 2016 (1)
October 2016 (4)
September 2016 (5)
August 2016 (2)
July 2016 (2)
June 2016 (3)
May 2016 (2)
April 2016 (3)
March 2016 (3)
February 2016 (1)
January 2016 (2)
December 2015 (2)
November 2015 (1)
October 2015 (4)
September 2015 (5)
August 2015 (2)
July 2015 (2)
June 2015 (2)
May 2015 (1)
April 2015 (2)
March 2015 (1)
February 2015 (1)
January 2015 (1)
December 2014 (2)
November 2014 (1)
October 2014 (1)
September 2014 (2)
August 2014 (1)
July 2014 (2)
June 2014 (1)
May 2014 (2)
April 2014 (1)
March 2014 (2)
+1 800 256 3608 (toll-free North America only)