oBrw:report() how can you control fonts etc. in the print.

oBrw:report() how can you control fonts etc. in the print.

Postby hag » Tue Sep 02, 2008 7:06 pm

I really like the ability to move browse column around. Biggest problem now is to print the browse after altering it.

I'm using oBrw:report() but I need the ability to size the print and cut it off when reaching a particular record.\
Any suggestions on how to accomplish this?
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Postby James Bott » Tue Sep 02, 2008 7:33 pm

>I'm using oBrw:report() but I need the ability to size the print and cut it off when reaching a particular record.\

I'm not sure what you mean by "size the print." If you mean change the size of the font, then you would either have to modify the xbrowse source or create a subclass because the font size of xBrowse:report() is hardcoded.

You can filter or scope the database anyway you want before calling the Report() method.

If you want more control of the report then I suggest using TReport instead.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby hag » Tue Sep 02, 2008 8:22 pm

>I'm not sure what you mean by "size the print." If you mean change the size of the font, then you would either have to modify the xbrowse source or create a subclass because the font size of xBrowse:report() is >hardcoded.

Yes change the font.

> You can filter or scope the database anyway you want before calling the Report() method.

Filter and scoping is working fine.

Two problems...it is using the size front from the browse which is OK for screen but to font is to large for the print. Goes off the page.

And it prints 6 extra pages. Won't stop at the last recored to print.


>If you want more control of the report then I suggest using TReport instead.

Not sure what treport is. Is that the regulat printing which I currently use or something else?

Harvey
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Postby nageswaragunupudi » Tue Sep 02, 2008 10:09 pm

Mr Harvey and Mr James

>
If you mean change the size of the font, then you would either have to modify the xbrowse source or create a subclass because the font size of xBrowse:report() is hardcoded.
...
If you want more control of the report then I suggest using TReport instead.
>

We can do with oBrw:Report( ... ) method itself, most of what we can do writing separate report using TReport. oBrw:Report( ... ) puts that flexibility in our hands through its bSetUp parameter.

There is no need to change the XBrowse code or subclass the method.

Syntax:
oBrw:Report( <cTitle>, ;
<lPreview>,;
<lModal>, ;
<bSetUp>, ; // xbrowse calls this codeblock for our setup
<aGroupBy> )

<aGroupBy> :
If we want a grouped report, we need not write separate report program.
Just giave an array of coulmns to be grouped on. This is very powerful feature.
Reduces a lot of our coding effort.

Now what is relevant for this subject is the bSetUp parameter

We can call oBrw:( ctitle, , , { |oRep,oBrw| MyReportSetup( oRep, oBrw ) } )

our function:
func MyReportSetUp( oRep, oBrw )


Here we have the report object that is created by the browse and the browse object. This function is called after creation of the browse object and before creation of the columns.

We can do any elaborate settings of the Report object here.

oRep:aFont already has two fonts built by the browse object
oRep:aFont[ 1 ] is Tahoma size 0,-8
oRep:aFont[ 2 ] is Tahoma size 0,-8 bold

we can substitute our own fonts or add fonts

We can or reset any properties of the report object.

Define our own columns if we want to.

Finally return control to the browse to continue printing.

return .t. if we do not want xBrowse to creat the columns.
return <.f. or nil> if we want xbrowse to create the columns

After xbrowse introduced this method, I practically stopped writing separate report modules.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby nageswaragunupudi » Tue Sep 02, 2008 10:17 pm

I have used the bSetUp parameter to great advantage. All my reports linked to browses now use oBrw:Report( ... ) method with my own settings made through bSetUp parameter.

I have a suggestion to Mr Antonio. While using this feature I found the need to call the bSetUp block twice at two stages. Now this is called before creation of the columns. Many times I need to modify some of the columns that are created. I have made modification in my variation of xbrowse, to call this method twice. Once before creating the columns and second time before activating the report. I have added a third parameter to indicate if it is the first or second call. With this I have the total control and I am able to do anything that I can do by writing a separate report module.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby James Bott » Tue Sep 02, 2008 10:18 pm

Harvey,

>And it prints 6 extra pages. Won't stop at the last recored to print.

I suspect this is a problem with you browse definition--I am not seeing that problem here. Try creating a very simple browse and see if it works OK for you.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby hag » Wed Sep 03, 2008 12:49 am

Rao and James

having a problem with the info sent. See code:
In mYreportSetUp() get compile error..."incorrect statement or unbalanced delimiters".

If i change it to: Define font oRep:aFont[1] name "arial" size 3.75,7
it prints so small can't be read and even though font is so small it still doesnt print all the columns of the browse.

What am I doing wrong?


Code: Select all  Expand view  RUN

if msgYesNo("oReport?")
   oBrw:report( "Guess who", , , { |oRep,oBrw| MyReportSetup( oRep, oBrw,msize ) } )    
   return nil      
endif
   
func MyReportSetUp(oRep,oBrw)
   oRep:aFont[1]
   return nil
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Postby nageswaragunupudi » Wed Sep 03, 2008 1:32 am

>
In mYreportSetUp() get compile error..."incorrect statement or unbalanced delimiters".
>
Please see this line:
Code: Select all  Expand view  RUN
   oRep:aFont[1]

This obviously gives a syntax error. First please resolve syntax errors at your end.

>
If i change it to: Define font oRep:aFont[1] name "arial" size 3.75,7
it prints so small can't be read and even though font is so small it still doesnt print all the columns of the browse.
>
Naturally.
You should print what it fits on the paper.

You can also configure the columns of report object to print one value under another value so that in one print column you can print information relating to two or more fields in the database. Please review samples on report how to do this. Then in you setup function you can configure the columns accordingly
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby nageswaragunupudi » Wed Sep 03, 2008 2:02 am

Here is a quick sample for using bSetUp codeblock. This sample uses the customer.dbf in the \fwh\samples folder.

Please compile and run this program in the samples directory. Then please go through the code, samples on making reports in the samples folder and then suitably adopt to your needs.
Code: Select all  Expand view  RUN
#include 'fivewin.ch'
#include 'xbrowse.ch'
#include 'report.ch'

REQUEST DBFCDX

function Main()

   local oWnd, oBrw, oBar, oPrnFont

   USE CUSTOMER NEW ALIAS CUST SHARED VIA 'DBFCDX'

   DEFINE WINDOW oWnd

   @ 0,0 XBROWSE oBrw OF oWnd

   oBrw:CreateFromCode()
   oWnd:oClient   := oBrw

   DEFINE BUTTONBAR oBar OF oWnd SIZE 80,32 2007
   DEFINE BUTTON OF oBar PROMPT 'Print' ;
      ACTION oBrw:Report( 'TestReport', , , ;
      { |oRep, oBrw, oFont| MySetUp( oRep, oBrw, @oPrnFont ) } )

   ACTIVATE WINDOW oWnd
   RELEASE FONT oPrnFont

return nil

static function MySetUp( oRep, oBrw, oFont )

   DEFINE FONT oFont NAME 'ARIAL NARROW' SIZE 0,-9 OF oRep:oDevice

   oRep:aFont[ 1 ]   := oFont

   COLUMN DATA CUST->First,CUST->Last,'' ;
         TITLE 'Name','','' SIZE 20

   COLUMN DATA CUST->STREET,CUST->ZIP ;
         TITLE 'Address','' SIZE 30

   COLUMN DATA CUST->City,CUST->State,'' ;
         TITLE 'City','State','' SIZE 20

   COLUMN DATA CUST->HIREDATE, ;
               If( CUST->Married, 'Married','Single' ) ;
          TITLE 'HireDate','Status' ;
          SIZE 10

   COLUMN DATA CUST->Salary, CUST->Age ;
         PICTURE '999,999,999' ;
         TOTAL ;
         TITLE 'Salary','Age'

return .t.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby James Bott » Wed Sep 03, 2008 2:28 am

Harvey,

>DEFINE FONT oFont NAME 'ARIAL NARROW' SIZE 0,-9 OF oRep:oDevice

> oRep:aFont[ 1 ] := oFont

Note how he uses the OF clause. If you don't do this you will get very tiny font sizes. The font needs to be built using the resolution of the print device (the printer in this case).

Also, to specify font sizes in points, use 0,-9 where the negative number is the size in points. The first number is always zero.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby hag » Wed Sep 03, 2008 5:31 am

Rao & James.

After all of your help its working just great. :D

Only thing now is to stop it from printing 6 extra pages. :?

Thanks to you both for your help.


Harvey
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Postby James Bott » Thu Sep 04, 2008 12:21 pm

NageswaraRao,

>DEFINE FONT oFont NAME 'ARIAL NARROW' SIZE 0,-9 OF oRep:oDevice

> oRep:aFont[ 1 ] := oFont

In this case, I think that you need to end the existing font before assigning a new one, or there will be a resource leak. So, it should be:

oFont:end()
DEFINE FONT oFont NAME 'ARIAL NARROW' SIZE 0,-9 OF oRep:oDevice
oRep:aFont[ 1 ] := oFont

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby nageswaragunupudi » Thu Sep 04, 2008 1:14 pm

Mr James.

I agree with you. But please consider this.

Should it be

oRep:aFont[ 1 ]:End()
DEFINE FONT oFont NAME 'ARIAL NARROW' SIZE 0,-9 OF oRep:oDevice
oRep:aFont[ 1 ] := oFont

?

Then we do not have to release this new font again in our program, because Report object releases all font objects in the DATA aFonts array. Then in my sample above, passing the new font by reference to the main program and releasing the font in the main program is not necessary.

Now I have looked at Report method in xbrowse.prg. The method creates two fonts, oFont and oBold, but at the end releases only one oFont. Fix is needed to release oBold also.

Do you think I am right ?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby James Bott » Thu Sep 04, 2008 1:28 pm

NageswaraRao,

>Should it be

>oRep:aFont[ 1 ]:End()
>DEFINE FONT oFont NAME 'ARIAL NARROW' SIZE 0,-9 OF oRep:oDevice
>oRep:aFont[ 1 ] := oFont

Since oRep:aFont[ 1 ] is just a pointer to oFont then either way will do the same thing.

>Now I have looked at Report method in xbrowse.prg. The method
>creates two fonts, oFont and oBold, but at the end releases only one
>oFont. Fix is needed to release oBold also.

>Do you think I am right ?

As you have pointed out, TReport is already releasing both the fonts, so I think that the xbrowse:report method does not need to. Even though it is doing oFont:end(), the font has already been released by TReport. This may even have a negative effect by reducing the font could by one more than it should be.

Comments, Antonio?

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby nageswaragunupudi » Thu Sep 04, 2008 2:16 pm

Mr James

The contents of oRep:aFont are not just pointers to the font objects provided by us. Report object creates new font objects afresh, with the identical specs for the "device" and stores them in ::aFont array. So these fonts are different objects. Report object releases only the fonts created by it. So the font objects we provided are to be released by us in the calling program later. You may please go through the New method of report.prg.

You may now look at my statement in the light of the above.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 32 guests

cron