Author Topic: Error changin swimlane colors  (Read 3532 times)

Martin Terreni

  • EA User
  • **
  • Posts: 672
  • Karma: +0/-0
  • Sorry, I can't write
    • View Profile
Error changin swimlane colors
« on: March 18, 2008, 10:24:17 pm »
Hi,
I have a tamplate diagram with all the standard swimlane colors.
other poeple have created diagrams with same name, but different colors.
Now I want to run a peace of code to aling the colors, but I keep geting an error that the memory Im trying to change is protected.
here is the code:
Code: [Select]
EA.Diagram template = Repository.GetDiagramByID(120);
            EA.Diagram tDiag;
            string msg = "";
            int i, j, k;
            textBox1.Text = " ";
            //loop for all diagrams
            for (k = 1; k < 386; k++)
            {
                //skip template diagram
                if (k == 120)
                    continue;
                try //in case no such ID
                {
                    tDiag = Repository.GetDiagramByID(k);
                    if (tDiag.DiagramGUID == null)
                        continue;
                }
                catch
                {
                    continue;//do nothing, I dont care
                }
                try
                {//loop for each swimlane in diagarm
                    for (i = 0; i < tDiag.SwimlaneDef.Swimlanes.Count; i++)
                    {//loop for each swimlane in template
                        for (j = 0; j < template.SwimlaneDef.Swimlanes.Count; j++)
                        {//are they the same swimlane?
                            if (template.SwimlaneDef.Swimlanes.Items(j).Title == tDiag.SwimlaneDef.Swimlanes.Items(i).Title)
                            {
                                msg = template.SwimlaneDef.Swimlanes.Items(j).Title + "," + tDiag.SwimlaneDef.Swimlanes.Items(i).Title + "," + tDiag.Name + "," + tDiag.SwimlaneDef.Swimlanes.Items(i).BackColor + "," + template.SwimlaneDef.Swimlanes.Items(j).BackColor + ",i=" + i + ",total:" + tDiag.SwimlaneDef.Swimlanes.Count + ",j=" + j + ",total:"+template.SwimlaneDef.Swimlanes.Count;
                                //the following statement throws error changin protected memory. I tried it also without casting
                                tDiag.SwimlaneDef.Swimlanes.Items(i).BackColor = (int)template.SwimlaneDef.Swimlanes.Items(j).BackColor;
                                textBox1.Text = textBox1.Text + msg + System.Environment.NewLine + "-----------------------------------------------------------" + System.Environment.NewLine;
                                j = template.SwimlaneDef.Swimlanes.Count;  //if found, then no need to keep on looking.                            
                            }
                        }
                    }
                }
                catch(System.Exception err)
                {
                    textBox1.Text = textBox1.Text = textBox1.Text + "(failed) " + msg + "," + err.ToString() + System.Environment.NewLine + "-----------------------------------------------------------" + System.Environment.NewLine;
                }
                

And here is some out put (I feiled to notice any indexing issue here):
Code: [Select]
Caller/User,Caller/User,Create Contact/Customer,16771561,16771561,i=0,total:3,j=0,total:32
-----------------------------------------------------------
(failed) Caller/User,Caller/User,Pre-Negotiation Provide Wireless via Call Center,0,16771561,i=0,total:6,j=0,total:32,System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at EA.SwimlaneClass.set_BackColor(Int32 pRet)
   at CS_AddinTaggedCSV.Form3.button2_Click(Object sender, EventArgs e) in C:\Documents and Settings\martinte\My Documents\Visual Studio 2005\Projects\CS_AddinTaggedCSV\CS Addin\Form3.cs:line 64
-----------------------------------------------------------
(failed) Caller/User,Caller/User,Find Caller,16771561,16771561,i=0,total:3,j=0,total:32,System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at EA.SwimlaneClass.set_BackColor(Int32 pRet)
   at CS_AddinTaggedCSV.Form3.button2_Click(Object sender, EventArgs e) in C:\Documents and Settings\martinte\My Documents\Visual Studio 2005\Projects\CS_AddinTaggedCSV\CS Addin\Form3.cs:line 64
-----------------------------------------------------------
(failed) Ordering UI,Ordering UI,Negotiation Provide Wireless via Call Center,12639424,14803425,i=1,total:9,j=7,total:32,System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at EA.SwimlaneClass.set_BackColor(Int32 pRet)
   at CS_AddinTaggedCSV.Form3.button2_Click(Object sender, EventArgs e) in C:\Documents and Settings\martinte\My Documents\Visual Studio 2005\Projects\CS_AddinTaggedCSV\CS Addin\Form3.cs:line 64
 
Notice that not all of then fail.
Thanks for any help!
Recursion definition:
If you don’t understand the definition read "Recursion definition".

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Error changin swimlane colors
« Reply #1 on: March 18, 2008, 11:49:32 pm »
Just guessing here, but...

Try defining i and j as short (int16).

Try explicitly creating the swimlane objects. You will have to use Collection.GetAt and cast the result.

Does it work now?
No, you can't have it!