![]() |
#1
|
|||
|
|||
![]()
I looked through the documentation about GMSManager.RunMacro, which I suposed that may do the job.
However I can not think out at the moment, how can I create an object from a specified class, if the function parameter is string with class name. I tried some "shots in the dark" by using CreateObject and GetObject functions, but as my class is not ActiveX - they did not suceeded. I want this to be as much generic, as possible. So if there is way not to use hardcoded constructor calls in the code, I would like to know that way. Kind Regards, Zlatin |
#2
|
|||
|
|||
![]()
I also tried using MSScriptControl.ScriptControl ActiveX control, Eval method.
Another thing I tried is adding a referrence to the GMS that contains the class module. However I cannot instantiate Private classes outside the GMS. When I change the Instancing property of Class module to PublicNotCreatable I can define a variable of type of the class in question, but I cannot actually instantiate the class. |
#3
|
||||
|
||||
![]()
Zlatin,
I suppose you will ensure that the two GMS modules are installed at the same time because you are trying to use some specific information (class) provided by the other GMS. In this case, the best bet is to add a reference from one GMS to the other. Here is an example. I created two new GMS modules and called them Project1.gms and Project2.gms. Then I started CorelDRAW and renamed the project names from GlobalMacros to Project1 and Project2 respectively. I added the following class module to Project2 and named it clsMyModule: Code:
Option Explicit Public strName As String Public nAge As Integer Public Sub ShowMessage() MsgBox "Name = " & strName & vbCr & "Age = " & nAge End Sub Since VBA doesn't allow to create public creatable classes (unlike VB), you need to provide a function that can create an instance of this class. So, just add a module to Project2 and paste the following code in it: Code:
Option Explicit Public Function CreateMyClass() As clsMyClass Set CreateMyClass = New clsMyClass End Function Code:
Option Explicit Sub Test() Dim c As Project2.clsMyClass Set c = Project2.CreateMyClass c.strName = "Some Name" c.nAge = 20 c.ShowMessage End Sub |
#4
|
||||
|
||||
![]()
I see that you just almost answered your own question while I was writing my reply.
However after some further testing I discovered that CorelDRAW doesn't shutdown properly if GMS cross-reference each other. Which is apparently a bug and should be looked at by Corel. Maybe you should create a real COM object using VB or C++ and then just instantiate it in your macro? |
#5
|
|||
|
|||
![]()
Ok, thank you, will try it right now.
Btw. I tried creating a function that will create a private class instance and return reference to it as an Object. However as soon as I try to call that function through GMSManager.RunMacro it fails on the moment that the reference should be passed accross boundaries of GMS module. And after it fails the Application Recovery Manager Wizard pops-up. I add this info, just in case someone else tries to do such things. Edit: Nope I do not like to create COM object. Also I am sure there would be no cross references between GMS modules. So there will be only one common GMS module that is referenced by other GMS modules. |
#6
|
|||
|
|||
![]()
Thanks Alex, works like charm.
I added a module named Constructors to my "common" GMS, that would contain all such functions for creating class instances. So I create a constructor function like Code:
Public Function ClassName() As ClassName Set ClassName = New ClassName End Function Code:
Dim oClassName As CommonGMSName.ClassName Set oClassName = CommonGMSName.Constructors.ClassName() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Palette (or Colors array) property in VBA class in CDR12 | zlatev | CorelDRAW/Corel DESIGNER VBA | 7 | 22-02-2005 12:28 |
Can I create CustomShape with VBA for CD? Can I create tool? | Jab | CorelDRAW/Corel DESIGNER VBA | 0 | 01-02-2005 06:02 |
Where does COrelPhotopaint 12 keeps its Globalmacros file? | cyrilgupta | Corel Photo-Paint VBA | 1 | 08-11-2004 16:02 |
How Do I set the PP object? | andyb | Corel Photo-Paint VBA | 2 | 30-05-2004 00:04 |
Font Substitution Upon Import | RobC | CorelDRAW/Corel DESIGNER VBA | 4 | 11-03-2003 00:06 |