Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Gerhard on March 21, 2005, 12:04:07 pm
-
Hi, I have the following code in a macro in WORD:
Sub CleanConstraints()
'
' CleanConstraints Macro
' Macro created 21-03-2005
'
Dim App As Object
Dim counter As Integer
Dim i As Integer
Dim J As Integer
Dim k As Integer
Dim MyModel As Object
Dim MyPackage As Object
Dim MyElement As Object
Set App = CreateObject("EA.APP")
App.Repository.OpenFile ("teste.EAP")
For counter = 0 To App.Repository.Models.Count - 1
Set MyModel = App.Repository.Models.GetAt(counter)
For i = 0 To MyModel.Packages.Count - 1
Set MyPackage = MyModel.Packages.GetAt(i)
For J = 0 To MyPackage.Elements.Count - 1
Set MyElement = MyPackage.Elements.GetAt(J)
If MyElement.Stereotype = "table" Then
Set ob = MyElement.Constraints.AddNew("Appended", "Type")
ob.Update
For k = 0 To MyElement.Constraints.Count - 1
Set ob = MyElement.Constraints(k)
If ob.Name = "Appended" Then
MyElement.Constraints.DeleteAt k, False
End If
Next
End If
Next
Next
Next
App.Repository.CloseFile
End Sub
When it reaches Constraints.deleteAt it gives an Internal Application Error.
This also happens in Delphi, with the same code
I did not test it with VB, only Delphi and VBA. I guess there is some problem with the automation collection's ?
I'm using the latest trial version
can somebody test this? or give an hint?
Thanks a lot
Regards
-
It doesn't work here either. I once had an issue related to collections.
> The method GetByName does not return a result on
> Repository.Issues The same applies to .Tasks (and others?)
You're right, only Models, Packages, Elements and Diagrams collections
support the GetByName method, all other collections should return
"Action not supported."
In these cases it is necessary to iterate though the collection testing
the name value explicitly.
Maybe the DeleteAt is not implemented correctly?
-
I'm not really into VB, but the collection handling isn't really correct. Once you delete one item from the collection, the 'k' index that you use already points to the next item. You might at least consider decreasing k with one when a delete has been issued. And I'm not sure if the "MyElement.Constraints.Count - 1" is evaluated once (at the start) or every time the loop starts. If it's the first case and you delete one item, your index 'k' runs higher than the collection size.
-
I'm not really into VB, but the collection handling isn't really correct. Once you delete one item from the collection, the 'k' index that you use already points to the next item. You might at least consider decreasing k with one when a delete has been issued. And I'm not sure if the "MyElement.Constraints.Count - 1" is evaluated once (at the start) or every time the loop starts. If it's the first case and you delete one item, your index 'k' runs higher than the collection size.
Hi,
I See your point, but that part was taken from the sample code on the default EA instalation.
However I have thought of that. If instead of the loop I simply put "DeleteAt 0, False" (knowing it exists constraints) it gives the same error! So It's not due to the index loop :(
thanks for your reply
Regards
-
It doesn't work here either. I once had an issue related to collections.
Maybe the DeleteAt is not implemented correctly?
Hi,
Maybe, Im not sure, however my code is based on the sample code EA installs : \Code Samples\VB_Sample\VB_Sample.frm
So it should work ???
Thanks
Regards
-
The code is absolutely correct. The DeleteAt has the False parameter to indicate that the index is not to be changed. Only after invoking refresh, the index should be renumbered. So I think this is a bug and should be reported to Sparx.
-
The code is absolutely correct. The DeleteAt has the False parameter to indicate that the index is not to be changed. Only after invoking refresh, the index should be renumbered. So I think this is a bug and should be reported to Sparx.
Hi, Thanks for your reply.
What is the procedure to report bugs to the author?
Thanks
Regards
-
On Sparx home page: http://www.sparxsystems.com.au/bug_report.htm