OberonPlace.com Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 17-05-2011, 11:17
Jeff
Guest
 
Posts: n/a
Default Comparing CorelDRAW.Document Objects

Hello,

I'm pretty new in Corel programming so I hope I don't ask too ridiculous things but I start to like Corel Automation and getting into it step by step is fun.

I'm referencing Corel X4 with CSharp 2005 and wonder, what's the right way to compare Document Objects in like this situation:

Code:
List<CorelDRAW.Document> docs = new List<CorelDRAW.Document>();
CorelDRAW.Document doc = app.createDocument();
docs.add(doc);
I bind to the QuerySave Event like so:

Code:
app.QueryDocumentSave += new CorelDRAW.DIDrawApplicationEvents_QueryDocumentSaveEventHandler(onQueryDocumentSave);
And get successfully called on a save event in my function:

Code:
void onQueryDocumentSave(CorelDRAW.Document Doc, ref bool Cancel)
{
   // Doc is the document where the event happend. But what is the corresponding document in my list?
   foreach(CorelDRAW.Document d in docs)
   {
      if(d == Doc)
           // do sth

      if(d.Equals(Doc))
           // do sth
   }
}
I suspected that the == operator might be overloaded for Document so that Corel internally identifies it's docs but it does not seem to be the case. A name comparison can of course also not be done since it's not unique among the opened docs.

Any ideas on this?

Best,

-Jeff
Reply With Quote
  #2  
Old 17-05-2011, 12:46
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Documents

Hey Jeff welcome to the forum. I don't have C# on this machine, so I did a quick test in VBA, and the equals does work in VBA.
Code:
Private Sub GlobalMacroStorage_QueryDocumentSave(ByVal Doc As Document, Cancel As Boolean)
    Dim d As Document
    
    For Each d In Documents
        If d = Doc Then
            MsgBox "match"
        Else
            MsgBox "no match"
        End If
    Next d
End Sub
-Shelby
Reply With Quote
  #3  
Old 18-05-2011, 03:19
Jeff
Guest
 
Posts: n/a
Default

Hello Shelby,

thanks for looking into this! I narrowed it down further, even without the List, kind of like so:

Code:
// global scope:
CorelDRAW.Document my_doc = null;

// --- then in a func:
CorelDRAW.Application app = new CorelDRAW.Application();
app.Visible = true;
app.QueryDocumentSave += new CorelDRAW.DIDrawApplicationEvents_QueryDocumentSaveEventHandler(onQueryDocumentSave);

my_doc = app.CreateDocument();
doc1.Name = "My Doc";
with event func:

Code:
void onQueryDocumentSave(CorelDRAW.Document Doc, ref bool Cancel)
{
   if(my_doc == Doc)
         MessageBox.Show(Doc.Name);
}
Which does not work either. I think the reason might be that the Parameter "Doc" is not being passed by "ref" so I don't get the original Document Objects but a copy and therefore the comparison fails.

So I'm definitely missing something, there sure must be a way to compare documents but I don't understand why Corel gives me a copy of the source Document where the event happend.

Best,

-Jeff

Last edited by Jeff; 18-05-2011 at 04:12.
Reply With Quote
  #4  
Old 18-05-2011, 04:46
Jeff
Guest
 
Posts: n/a
Default

UPDATE: at last I found the Property

Code:
CorelDRAW.Document.MetaData.DocID
so this obviously is the right way to compare two Documents if they are different Objects (which automatically is the case in Event handling since Corel does not pass them by ref in CSharp):

Code:
if(doc1.Metadata.DocID == Doc.Metadata.DocID)
    // do sth...
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
Rotate All Objects in current document derasje Macros/Add-ons 2 15-11-2008 05:07
Is it possible to make an invisible document in coreldraw ? enpassant CorelDRAW/Corel DESIGNER VBA 2 12-07-2006 10:16
Objects in Document akayani Code Critique 9 06-02-2006 07:15
How to get objects from another opened corel document ama CorelDRAW/Corel DESIGNER VBA 12 24-02-2004 07:11
Copying objects to clipboard then closing document. CORNMEN CorelDRAW/Corel DESIGNER VBA 4 31-03-2003 09:52


All times are GMT -5. The time now is 06:47.


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