Oh ya, you might want to call objItem.IdentifyClass to see if it really is a class before you nuke it.
-----Original Message-----
From: Hsia, John
Sent: Friday, February 22, 2002 11:24 AM
To: '"G�ntsch, Alexander"'; 'Rose Forum'
Subject: RE: (ROSE) Developing addins: Deleting a RoseItem

In general, I'm not sure if deleting a model element as a response to a creation event is a safe thing to do as Rose may not be finished creating the new model element.  Please verify that you're not getting any weird side effects.  Anyways, embedded comments in your code follows ...
-----Original Message-----
From: "G�ntsch, Alexander" [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 15, 2002 8:58 AM
To: 'Rose Forum'
Subject: (ROSE) Developing addins: Deleting a RoseItem

Hello,
 
I'm just about developing an addin for rose and trying to implement the following functionality:
 
In certain cases the user is not allowed to create a new class (for example by clicking the class icon in the toolbar and then in the diagram).
 
So I registered for the NewModelElementEvent and try to delete the class afterwards:
 
Public Sub OnNewModelElement(objRoseApp As RoseApplication, objItem As RoseItem)
    
...
    
    If aktuelleAnsicht <> ANSICHT.MODELL Then
        Dim res As VbMsgBoxResult
        Dim aktModell As RoseModel
        res = MsgBox("...Message...", vbOKOnly, "Error")
[Hsia, John] You may have to typecast the roseitem back to a class.  In VB, that code would look like
dim myClass as RoseClass
set myClass = objItem
        aktModell = objRoseApp.CurrentModel
[Hsia, John] missing the set - i.e. "set aktModell = ..." 

        MsgBox "Name " + objItem.Name + aktModell.GetAllClasses.GetWithUniqueID(objItem.GetUniqueID).Name ' for debug purposes
        aktModell.RootCategory.DeleteClass (aktModell.GetAllClasses.GetWithUniqueID(objItem.GetUniqueID))
[Hsia, John] Usually, I delete the class from the parent category for that class not the root category.  You're assuming that the class belongs to the logical view - it may not. 
    End If
  
End Sub
 
What happens is: When I create a class (and the condition aktuelleAnsicht <> ANSICHT.MODELL is true) the first msgbox appears but not the second one (the one beginning with "Name").
 
So: If I have a RoseItem that is a class, how can I delete it?
 
Thank you in advance,
 
Alexander

Reply via email to