ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  makeTmpFile questions and problems
Posted by Andrew on Apr-25-2013 02:02
So I'm working in VBA (in Access), and I'm trying to use makeTmpFile so I can then set an Image control to show the resulting image....the files are being created ok - they're even being displayed ok, but for some reason, things are very flakey. By that, I mean it's actually causing Access to crash.

I haven't been able to figure out exactly why, by I'm leaning toward the makeTmpFile, for sure...It's crashing just after the image is created and is displayed. I'm wondering if it's crashing when it's trying to delete those tmp files, because if never seems to actually delete them.

Is there another way to do this? Ideally, I'd just use MakePicture and set my Image control's PictureData to that...but that doesn't work, because MakePicture is creating the wrong type of image for PictureData.

Any ideas? I need this thing to be stable, obviously....I'm now starting to think that I need to go back to the drawing board and figure out how to get the CD ocx working without admin rights.

  Re: makeTmpFile questions and problems
Posted by Peter Kwan on Apr-25-2013 07:57
Hi Andrew,

In the Excel sample code in my previous message, there is a function "Private Function loadCD() As Object" that loads the manifest, so as to support registration free components. In the function, there is a variable called "cdSave". This variable must be declared as a global variable in a VBA Module (not in the Form). Just create a module called "Module1" (or any other name), and put one line of code in:

Public cdSave As Object

If you declare the above variable in the Form instead, then once a chart is shown, and you close the form and open it again, it will crash.

For the makeTmpFile, everytime it is called, before it creates the temporary file, it will check if there are any previous temporary files created in the directory that have exceeded their lifetime (default 600 seconds), and deletes them. No files will be deleted if the makeTmpFile is not called again, or if the files are not older than the lifetime.

The makeTmpFile is usually used in web applications. In these applications, there can be many users viewing the web site, and a single user can open multiple browser windows. So we cannot use a hard coded filename, otherwise the users will overwrite each other's files. We cannot delete the file immediately after sending the file to the browser, because the browser can ask for re-transmission later (due to unreliable networks, the browser may not receive the file, or may receive the file corrupted, so it may ask for re-transmission). That's why the makeTmpFile uses a timeout to decide when a file can be deleted.

For desktop applications, you may just use a hard coded filename, and delete the file immediately after setting it to the Image control, like:

Call c.makeChart(pathToImageFile)
myImageControl.Picture = pathToImageFile
Kill pathToImageFile

For the BaseChart.makePicture, it returns an IPicture object, which is a standard object in Windows, and is the same as the object returns in the standard VBA LoadPicture function. I check the Microsoft documentation and finds out this object cannot be used for the MS Access image control (which is a bit surprising to me).

http://msdn.microsoft.com/en-us/library/office/aa172231(v=office.11).aspx

The PictureData property seems to be a proprietary format specific to Microsoft Access Image control. Its function seems to be to allow the code to store the image already in the control to somewhere, and then later loaded it back to the Image control. As the format of PictureData is not published, I cannot modify the code to fit its format. So I think the best method is to just use an image file.

Please let me know if the above can solve the problem.

Regards
Peter Kwan

  Re: makeTmpFile questions and problems
Posted by Andrew on Apr-25-2013 20:19
Ah - that does the trick....I did have the public var for cdSave, but I was using that for the chart operations, rather than the object returned by the function. That seems to have solved things, in conjunction with using makeChart...thanks for the help, again!

  Re: makeTmpFile questions and problems
Posted by Andrew on Apr-26-2013 03:47
So it seems that now the problem is that I can't get it to stop crashing in new versions of Access. Works fine in 2000, but 2010 and 2013 kepe crashing....that makes me wonder if it's some sort of security feature that's been added since 2000 that's killing it by preventing the manifest method from working?

  Re: makeTmpFile questions and problems
Posted by Peter Kwan on Apr-26-2013 13:29
Hi Andrew,

If you only need to support Windows 2003 or above, instead of using "Set cd = loadCD()", you may try:

Set ACTCTX = CreateObject("Microsoft.Windows.ActCtx")
ACTCTX.manifest = CurrentProject.Path & "\\cd.config"
Set cd = ACTCTX.CreateObject("ChartDirector.API")

In brief, you can remove the "loadCD" function entirely, and use "Microsoft.Windows.ActCtx" to load the manifest instead. According to Microsoft documentation, the "Microsoft.Windows.ActCtx" comes with Windows 2003 or later. For Windows XP, you can obtain ""Microsoft.Windows.ActCtx" by installing a component from Microsoft (but then it defeats the purpose of using registration free COM - you may just directly register or install the ChartDirector).

If the above still cannot solve the problem, please let me know. I will install MS Office 2010/2013 to test.

Regards
Peter Kwan

  Re: makeTmpFile questions and problems
Posted by Andrew on Apr-26-2013 20:18
Ah - got it! That does the trick...I just added a line to detect the Access version and then based on that, use the proper manifest load. Working fine in 2000, 2010 and 2013 now! Thanks very much for all the help - I think I'm all set now!