Monday, September 8, 2008

Workaround: Dangling Datasession Left After Running Report

In December, 2007, I posted about a bug in VFP 9 that causes a dangling datasession after running a report from form with a private datasession and using report listeners chained together as successors. Microsoft still hasn't fixed the problem, but I now have a workaround for the bug.

First of all ... I have to give credit where credit is due. I didn't come up with the solution. It was given to me by Rick Hawkins ... so thanks Rick!! But now that I have the solution, I want to share it with everyone who follows my blog (all three of you.)

The solution is actually quite simple ... just before you instantiate any report listener object, switch to datasession 1, instantiate the object, then switch back to the previous datasession.

LOCAL lnDataSession, loListener, loListener2

lnDataSession = SET('DataSession')
SET DATASESSION TO 1
loListener = CREATEOBJECT('ReportListener')
loListener.ListenerType = 1
loListener2 = CREATEOBJECT('ReportListener')
loListener.Successor = m.loListener2
SET DATASESSION TO (m.lnDatSession)

REPORT FORM Whatever OBJECT m.loListener


I'd rather Microsoft fix the bug, but I guess a workaround is the next best thing!

6 comments:

Anonymous said...

as one of the three, thank u for the tip, Cathy

Anonymous said...

as one of the other three, thank as well for the tip, Cathy :)

Furio Filoseta said...

He, he. I guess I'm the remaining one of the three. Thank you for sharing, Cathy, I was just discovering the bug and your timing was perfect.

Anonymous said...

You can count me among the three too.

(It's like the four books in the "Hitchhiker's Guide to the Galaxy" trilogy. *g*)

E. Huybrechts said...

Thanks for the great tip, I had to find workaround for this bug for years!

E. Huybrechts said...

Thank you so much, I had to fight this nasty bug for years.