OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old 06-06-2006, 14:52
RobC
Guest
 
Posts: n/a
Default Hallelujah!!

I think I've found a 100% workaround to the gif problem.

I started thinking about when the files flip from "invalid" to "valid". It always happens when my app closes, but sometimes happens when my app is open.

What happens always when an app closes and sometimes when it is running?

GARBAGE COLLECTION

Here is the whole routine

Code:
        Dim objDraw As New CorelDRAW.Application
        Dim pal As CorelDRAW.StructPaletteOptions
        Dim EXP As CorelDRAW.ExportFilter

        pal = objDraw.CreateStructPaletteOptions

        With objDraw.ActivePage
            .SelectShapesFromRectangle(0, 0, .SizeWidth, .SizeHeight, True)
        End With

        With pal
            .PaletteType = cdrImagePaletteType.cdrPaletteOptimized
            .NumColors = 16
            .Smoothing = 0
            .DitherType = CorelDRAW.cdrDitherType.cdrDitherNone
            .ColorSensitive = False
        End With

        EXP = objDraw.ActiveDocument.ExportBitmap("C:\" & TextBox1.Text & txtCount.Text & ".gif", CorelDRAW.cdrFilter.cdrGIF, CorelDRAW.cdrExportRange.cdrSelection, CorelDRAW.cdrImageType.cdrPalettedImage, 225, 225, 72, 72, CorelDRAW.cdrAntiAliasingType.cdrNormalAntiAliasing, False, False, False, False, CorelDRAW.cdrCompressionType.cdrCompressionNone, pal)
        
        With EXP
            .Interlaced = False
            .Transparency = 0 ' FilterGIFLib.gifNone
            .InvertMask = False
            .ColorIndex = 1
            .Finish()
        End With
        pal = Nothing
        EXP = Nothing
        objDraw = Nothing
at the end of my routine, I set all my object references to nothing. That doesn't mean that the objects are disposed of, only that I've told the system that I don't need them anymore. The disposal doesn't take place until the garbage collector is triggered. Normally in VB or VBA or C# the programmer doesn't have to worry about memory allocation (and it's inverse, garbage collection), the system manages it for us, but here is a case where we need to trigger it on demand.

so

Code:
.
.
.
EXP = Nothing
objDraw = Nothing
GC.Collect()
does the trick. Why isn't the gif file released when finish is called? I don't know the answer to that, but at least I have a way of forcing it to happen when i need it.

Thanks to everyone who followed the thread and provided help and insight. That was a tough one.
Reply With Quote
  #12  
Old 07-06-2006, 02:16
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

Quote:
Why isn't the gif file released when finish is called?
You may laugh but as I don't trust MS I would think that when you use "WITH" construction then a temporary object is created for compilation optimizations purposes (maybe, it shouldn't of course) - so when you call .Finish from inside of with, then it's not the last using of your export object, but "end with" is the last....

Try this
Code:
        With EXP
            .Interlaced = False
            .Transparency = 0 ' FilterGIFLib.gifNone
            .InvertMask = False
            .ColorIndex = 1
        End With
        EXP.Finish()
;-)
Reply With Quote
  #13  
Old 07-06-2006, 13:35
RobC
Guest
 
Posts: n/a
Default

Woxxom-

FYI, I tried your suggestion to not call the .finish method inside the 'with' structure. It still did not release. Your idea seemed plausible to me, as I've run into cases in Corel VBA where 'with' does not work correctly. This is not one of those cases.

Cheers,
Rob
Reply With Quote
  #14  
Old 10-06-2006, 11:41
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

Wow I just got the same problem inside CorelDRAW11 VBA macro I wrote.
The bug is in CorelDRAW11 which doesn't release file on export immediately and only AFTER macro SUB is finished. I figured out the solution - it took almost an hour! - I divided my sub into two subs - one does all exports, then sets winAPI timer (SetTimer) to 100ms and immediately exits. The other sub is called by Windows in 100ms and does all import processing in files stored in a private collection object which is saved between subs as it is declared in module head. It will be easy for you to do just the same if you encounter such problem inside VBA or if grabage collection takes more than several milliseconds (of course you can set timer not to 100ms but also to 20ms and maybe less, but something tells me that by default timer resolution in Windows is about 1/55 sec = 18 ms)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pdf Export Files Just Rewrite Over And Over sifterbox CorelDRAW/Corel DESIGNER VBA 10 13-12-2011 07:58
DXF export for CAD / CAM / CNC jemmyell CorelDRAW/Corel DESIGNER VBA 5 23-02-2006 10:28
HPGL export problem Anonymous General 1 16-02-2006 09:15
Export to JPG (I need serious help) liviazornio CorelDRAW/Corel DESIGNER VBA 14 14-11-2005 08:59
Problem with Export (or Save as) in AI-Format LOT CorelDRAW/Corel DESIGNER VBA 3 10-02-2004 14:28


All times are GMT -5. The time now is 13:05.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com