Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OLE Object gets corrupt on 2nd run in VFP9 only on Windows 7

Status
Not open for further replies.

vedamin

Programmer
Aug 24, 2021
5
0
0
IN
Following is a simple piece of code. It fails on 2nd run only on Windows7 but runs well on Windows 8 and 10.
The only solution is to quit VFP9 and run the code again.

oCR = CREATEOBJECT("CrystalRuntime.Application")
oRpt = oCR.OpenReport(FULLPATH('')+"SAMPLE.RPT")

oConn = CREATEOBJECT("ADODB.Connection")
oConn.ConnectionString = "Provider=vfpoledb;Data Source="+ FULLPATH('')+";Collating Sequence=general;"
oConn.Open

oRS = CREATEOBJECT('adodb.recordset')
oRS.Open("SELECT * FROM SWDAT.DBF", oConn)
oRpt.Database.SetDataSource(oRS) && Throws Error on 2nd run : OLE Object may be corrupt
oRpt.Database.Tables.Item(1).Parent.Verify()
 
Hi Vedamin,

I don’t know your application or Crystal Reports, but are you releasing the objects you created after your first run? Sometimes cleaning things up makes a difference.

Regards, Gerrit
 
I'd also try what Gerrit suggests. This means first check, if there still is an oRS recordset, that needs to be closed and released before creating a new one. You may also cause the problem because for a short time you pull away the recordset the report still displays.

Code:
...
if Vartype(oRS)="O"
   oRS.Close()
   oRS = .null.
endif
oRS = CREATEOBJECT('adodb.recordset')
oRS.Open("SELECT * FROM SWDAT.DBF", oConn)
...

Like Gerrit I didn't program Crystal Reports, but I assume there should be something like oRpt.Database.UnsetDataSource() or you do oRpt.Database.SetDataSource(.null.) or oRpt.Close() or anything releasing the report.

Chriss
 
I am using the following code at the end. But this hasn't worked.
oRS.Close
oConn.Close
RELEASE oRS
RELEASE oConn
RELEASE oRpt
RELEASE oCR

The SWDAT.DBF has a Field Type = 'General' for images.
This is the reason I have to take the "vfpoledb" route.


 
Vedamin,

I haven't used the most recent versions of Crystal Reports, and so my information might be out of date. But in general you don't use a VFP General field to insert an image into a report.

The preferred approach is not to store the image in your DBF, but rather to store its path and filename. Within your report, you add an image at the position where you want it to appear. Any image will do; this is just a place-holder. In the Format Editor for the image, you create a formula that sets the "graphic location" to the field containing the path and filename.

This will allow you to access the table in your report without having to use an ADO Recordset. You will be able to drill down in the Data Explorer to access either "Visual Foxpro Databases" or "Visual Foxpro Tables" (depending on whether the table is in a DBC). You can then address the table from within VFP by doing [tt]oRpt.Database.SetDataSource[/tt] in the usual way.

I think you will find this approach much simpler. But keep in mind what I said earlier about the information not necessarily being up to date.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks everyone.

As Gerrit and Mike suggested, I tried all possible ways to clear the memory.
The whole application runs without any problem under Windows 10. But under Windows 7 it fails on 2nd run.

I normally use Foxplus table with Crystal report. This is direct and does not require ADODB. But no support for General field.

Mike, as you suggested, the provision to print directly from path and filename is available in Crystal 11.
But I am using Crystal 9 and can't switch to 11 unless I find some way to distribute 11 library files along with my application.
 
Vedamin,

I think CR 9 supports the ability to print an image with a conditional formula. I don't have access to the software at the moment, but perhaps you can check that for yourself.

If that's right, you should certainly be able to use Foxplus tables, which - as you say - are supported directly within CR, without the need for ADODB or even ODBC.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

The option to print image from physical file (file names generated at runtime),
has been made available from version XI.

Vedamin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top