hiho,
Rose scripting, as is typical in languages supporting polymorphism, allows
upcasting during assignments but not downcasting. So an assignment of a
function or expression that returns ClassDiagram can be assigned to a
Diagram, but not vice versa.
With Patrick Kennedy's caveats regarding running the script from the menu,
this will work:
Dim theClassDiagram As ClassDiagram
Dim theDiagram As Diagram
' Next commented out line won't work:
' Set theClassDiagram = RoseApp.CurrentModel.GetActiveDiagram()
Set theDiagram = RoseApp.CurrentModel.GetActiveDiagram()
If theDiagram Is Nothing Then
' Happens when there is no active diagram
msgbox "Error: Script must be run from a class diagram"
ElseIf theDiagram.CanTypeCast(theClassDiagram) Then
Set theClassDiagram = theDiagram.TypeCast(theClassDiagram)
' Do work with theClassDiagram
msgbox theClassDiagram.Name
Else
msgbox "Error: Script must be run from a class diagram"
End If
------- b
--
Brian G. Lyons
Number Six Software - Voted Rational's Best Complementary Service Provider
1655 North Fort Myer Drive, Suite 1100
Arlington, VA 22209-3196
http://www.numbersix.com
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Manish Agrawal
Sent: Tuesday, September 04, 2001 11:58 PM
To: [EMAIL PROTECTED]
Subject: (ROSE) does rose script not allow polymorphic assignments?
Hi,
I was trying to do the following:
dim the Model as Model
dim objClassDiagram as ClassDiagram
set theModel = RoseApp.CurrentModel
set objClassDiagram = theModel.GetActiveDiagram() //error!!!
I get a compile time error on line 4 that the assigned variable and the
expression are of different types. Is this because "GetActiveDiagram"
returns a "diagram" and not a "ClassDiagram"? However I know that the
diagram being returned is a ClassDiagram. Can I do something to assign the
returned object reference to a ClassDiagram variable and not to a Diagram
variable?
Thanks and Regards
Manish
************************************************************************
* Rose Forum is a public venue for ideas and discussions.
* For technical support, visit http://www.rational.com/support
*
* Admin.Subscription Requests: [EMAIL PROTECTED]
* Archive of messages: http://www.rational.com/support/usergroups/rose/rose_forum.jsp
* Other Requests: [EMAIL PROTECTED]
*
* To unsubscribe from the list, please send email
*
* To: [EMAIL PROTECTED]
* Subject:<BLANK>
* Body: unsubscribe rose_forum
*
*************************************************************************