Author Topic: How to empty Parameters collection of an EA.Method  (Read 7589 times)

panfiluta

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
How to empty Parameters collection of an EA.Method
« on: January 26, 2009, 07:43:17 pm »
Hi all,

I've been dealing the problem with Parameters collection of an EA.Method class.

Main purpose of my add-in is to create a new class diagram using the information inserted by a user into the add-in form.

I've created a new class diagram, put some class and interface objects into it, and put a few methods into the classes using my add-in.

The problem appears when I'm trying to fill the Parameters collections of these methods. In this moment the Parameters collection already contains some parameters, added in the previous run of the add-in.

Is there a way to empty this collection so I can use my add-in properly?

Thanks all for help.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8083
  • Karma: +118/-20
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #1 on: January 27, 2009, 08:33:59 am »
Iterate over the parameters collection and delete each one.

panfiluta

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #2 on: January 27, 2009, 06:25:26 pm »
Yes, I've already tried that. I'm using C#, so here is my code:

Code: [Select]
EA.Method _method;
          EA.Collection l_ParamCol;
          l_ParamCol = _method.Parameters;
          
          for (short i = 0; i < l_ParamCol.Count - 1; i++)
          {
                _method.Parameters.Delete(i);
              
          }
          _method.Parameters.Refresh();

l_ParamCol.Count = 5 but the result is an error message: "EA_MenuClick: External Component has thrown an exception"



«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #3 on: January 27, 2009, 09:58:59 pm »
Which statement throws the exception?

What if you iterate downwards?
No, you can't have it!

panfiluta

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #4 on: January 27, 2009, 10:47:27 pm »
I tried to iterate downwards but the result is still the same - exception thrown.

My method now looks like this:
Code: [Select]

        public void DeleteParameters(EA.Method _methodObject)
        {  
            int i;
            for (i = _methodObject.Parameters.Count - 1; i >= 0; i--)
            {
                _methodObject.Parameters.Delete((short)i);
            }
            _methodObject.Parameters.Refresh();
        }
      

The exception is thrown by statement: _methodObject.Parameters.Delete((short)i);
when it is run for the first time.
« Last Edit: January 27, 2009, 10:54:21 pm by panfiluta »

PV

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #5 on: January 27, 2009, 11:11:21 pm »
Quote
I tried to iterate downwards but the result is still the same - exception thrown.

My method now looks like this:
Code: [Select]

        public void DeleteParameters(EA.Method _methodObject)
        {  
            int i;
            for (i = _methodObject.Parameters.Count - 1; i >= 0; i--)
            {
                _methodObject.Parameters.Delete((short)i);
            }
            _methodObject.Parameters.Refresh();
        }
      

The exception is thrown by statement: _methodObject.Parameters.Delete((short)i);
when it is run for the first time.

I could be wrong but I suspect the problem lies in the way you are looping through the collection. Since you are reducing the number of items in the collection in each loop, the line "for (i = _methodObject.Parameters.Count - 1; i >= 0; i--)" is going to end up getting confused..  ::)

maybe try something along these lines:

Code: [Select]

int _maxItems = _methodObject.Parameters.Count;
 
for (i = 0; i = _maxItems; i++)
{
    _methodObject.Parameters.Delete(0);
}


~ PV
« Last Edit: January 27, 2009, 11:15:09 pm by Praveshs »

panfiluta

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #6 on: January 27, 2009, 11:24:08 pm »
Hi PV,

thanks for your reply.

I tried your idea, unfortunately it doesn't solve my problem.
Problem is the program crashes in the first loop even with index = 0 .

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #7 on: January 27, 2009, 11:25:26 pm »
Perhaps, but EA generally does not complain until it reorders the collection. That should happen when you Refresh the set, which panfiluta is doing after the deletions are over.

What about the DeleteAt method? I would normally use this to force a Refresh, but perhaps you could look at it the other way. Try explicitly preventing a Refresh by setting the Boolean parameter to False.

David

PS: I should have asked earlier. What is the exception message (without the stack trace)?
No, you can't have it!

panfiluta

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #8 on: January 28, 2009, 01:08:26 am »
Hi David,

I tried the DeleteAt method with Boolean parameter set to False but this doesn't work either.

The only difference now is the error message which reads: ""System.Runtime.InteropServices.COMException"

The exception message is empty string in both cases.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #9 on: January 28, 2009, 05:23:28 am »
Not too informative is it...

What build of EA are you using?

For that matter, what happens if you try to access (one of) the objects in the collection? Do you get a valid object? Can you read its attributes, or manipulate them?

If you can successfully retrieve any of the objects in the collection, can you retrieve them all? Perhaps one specific object is causing the problem. That could be some issue with the object itself, or it could be something to do with the object being (for example) the first or last item in the collection.

If this persists when you reach this point, and if you still have the problem with Build 834, I suggest you send a bug report to Sparx. If you are a registered user, go to the Registered Users page and follow the bug report link near the top (in the first few paragraphs of text). That version of the bug report will allow you to attach a sample project as well as the code you are using. Remember to compress the files so servers along the way won't drop them.

David
No, you can't have it!

panfiluta

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #10 on: January 28, 2009, 07:22:47 pm »
I'm using Build 834. Is this build more bug-prone than others?

I can successfully retrieve all objects in the collection and read their attributes. I can also add new parameter into the collection using AddNew method. On the other hand I can't update content of the objects and can't delete any of these.

I'll give it one more try and probably send a bug report as you suggested.

Thank you for your help.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #11 on: January 28, 2009, 10:46:04 pm »
Build 834 is not more bug prone, in fact quite the opposite. It is the most recent (and final) build of EA 7.1 though. If you were not using it then it was worth updating before sending a bug report.

Since you can access all collection members, but not delete them, it seems like a collection issue. As far as not being able to modify the objects themselves, that could be something to do with the object itself. I was more interested in whether the object actually existed.

Sometimes EA returns a null reference when you access something that's not there. For example, when retrieving an element (or whatever) by GUID, if no such element exists EA will return a null reference rather than throwing an error.
No, you can't have it!

ALL_IN_ONE

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #12 on: July 06, 2009, 11:25:29 pm »
hello folks,

I am too facing the same problem. Unable to delete parameters which are existing from the last Add-in run. Tried the same techniques like deleteaAt, downward iteration  . .. but all in vain. I am using EA 7.5 Build 845. Can anybody please help me at the earliest.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #13 on: July 06, 2009, 11:59:25 pm »
Have you called Refresh() on the collection since the parameters were added? Note that you will have to refresh the collection from the thread where you want to do the removal, which might not be the one where the add-in ran. This is particularly important if you have the UI visible (i.e. the user may interact with your model) as your add-in is running.
No, you can't have it!

ALL_IN_ONE

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: How to empty Parameters collection of an EA.Me
« Reply #14 on: July 13, 2009, 07:23:53 pm »
hello all,

I am now able to dlete the parameters, but culd not figure out the problem how it showed the parameters of the last addin run? Now its working fine. Thank you all.

regards,
Darshan