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:
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):
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!