Friday, December 28, 2007

New VFP Magazine Announced!

Rather than retype what Rick Schummer did ... here's a link to his blog describing the new magazine by Rainer Becker:

Friday, December 7, 2007

Gotcha: Dangling Datasession Left After Running Report

If you run a report using a ReportListener from the FFC directory, and you're using a successor listener, and that report is run from a form with a private datasession, you end up with a dangling datasession after the report completes. If you keeping running reports in this manner, you keep building up more dangling datasessions. I don't think I have to tell you the consequences of a long day of running reports like this!

I posted this on Microsoft's Connect site so anyone who wants to confirm, vote, comment, etc. about this bug, the ID number is 316134.

Here are the steps to reproduce the problem:

1. Create a form
2. Set the datasession to private
3. Add a button with the following code in the click

lcReport = SYS(2015)

CREATE CURSOR junk (test I)
FOR ln = 1 TO 10


ThisForm.AddProperty('oListener', null)

SET CLASSLIB TO 'C:\Program Files\Microsoft Visual FoxPro
ThisForm.oListener = CREATEOBJECT('_ReportLIstener')
ThisForm.olistener.listenertype = 1

THisForm.AddProperty('o2', null)
ThisForm.o2 = CREATEOBJECT('ReportListener')
ThisForm.oListener.Successor = ThisForm.o2

REPORT FORM &lcReport OBJECT ThisForm.olistener

4. Run the form
5. Click the button
6. Close the report
7. Close the form
8. Open the data session window
9. Notice an Unknown(#) session.

Tuesday, December 4, 2007

Gotcha: Workaround for Data Group bug

I've had a few people ask for suggestions on how to work around the ugly data group bug that I previously blogged about. So far, the only work around I have is not generic and has to be applied to EVERY report that uses data groups. I HATE this solution, but it's the only one I have so far.

1. Create a report variable for any data you need to show in the Data Group Header. Set the expression to the data field. (rcCustomer)

2. Create a report variable to count the number of detail lines in the data group. Set the value to 0, Reset it on the data group, and set the Calculation to Count. (rnCustCount)

3. In the Data Group Footer, force the counter to zero after the data group by entering the following in the On Exit Expression: _VFP.SetVar('rnCustCount', 0)

4. In the field object in the Data Group header, enter the following in the Print When expression: rnCustCount = 0

5. Now copy the field object, but change the reference to the data field to refer to your report variable (rcCustomer). Then change the Print When to rnCustCount > 0. Just stack this on top of the original field object.

You now have two objects in the data group header. The original one prints only the first time the data group prints. The second one prints on subsequent pages and uses the report variable instead of the data reference so it will be the right record. An added bonus to this solution is that you can add the word "Continued" in the expression that prints on subsequent pages.