Swapping between multiple Documents

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by Justin Stenning - Manager, Research & Development, netcat.biz Pty Ltd
Version: 4.0.0235
Avatar
Hi,

I'm not sure whether I have hit a bug, or whether I am doing this wrong:

I have a single SyntaxEditor control, and I am swapping multiple Document objects into it when switching between tabs like this:

editor.Document = myDocument1;
However I have found that if I scroll down a document, make a selection, and then swap to another document about 1 out of 5 times the above line of code will generate an ArgumentOutOfRangeException.

Exception info:

System.ArgumentOutOfRangeException was unhandled by user code
  Message="Specified argument was out of the range of valid values.\r\nParameter name: index"
  Source="ActiproSoftware.SyntaxEditor.Net20"
  ParamName="index"
  StackTrace:
       at ActiproSoftware.SyntaxEditor.DocumentLineCollection.get_Item(Int32 index)
       at bm.b(Int32 A_0, Int32 A_1)
       at ActiproSoftware.SyntaxEditor.DisplayLineCollection.e(Int32 A_0)
       at ActiproSoftware.SyntaxEditor.EditorView.l()
       at ActiproSoftware.SyntaxEditor.EditorView.ArrangeCore()
       at ActiproSoftware.WinUICore.UIElement.Arrange(Rectangle newBounds)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.ArrangeCore()
       at ActiproSoftware.WinUICore.UIControl.Arrange(Rectangle newBounds)
       at ActiproSoftware.WinUICore.UIControl.UpdateLayout()
       at ActiproSoftware.WinUICore.UIControl.Invalidate(InvalidationLevels levels, InvalidationTypes types)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.a(co A_0)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.a(Document A_0)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.set_Document(Document value)
I have not yet tried creating a completely cut down test, however I have removed the syntax language and reproduced the error.

Is there something I should be doing before attempting to swap the Document object or is this a problem with SyntaxEditor?

In the short term I will create an editor for each document - however I would much prefer to use the document swapping method.

Cheers,
J

Comments (7)

Posted 17 years ago by Justin Stenning - Manager, Research & Development, netcat.biz Pty Ltd
Avatar
I believe I may have found where the problem is.

To reproduce, start with two documents, one longer than the other. Create a selection at the end of the larger document, then switch to the smaller. You should get the ArgumentOutOfRangeException every time.

I have got around the problem by resetting the selection prior to swapping the document object:

  ...
  editor.SelectedView.Selection.SelectRange(0, 0);
  editor.Document = myDocument1;
  ...
Cheers,
J
Posted 17 years ago by Justin Stenning - Manager, Research & Development, netcat.biz Pty Ltd
Avatar
With the above workaround I have had the ArgumentOutOfRangeException, however its frequency is significantly reduced.
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks Justin, we'll try and get this fixed as soon as possible.


Actipro Software Support

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Justin,

I've been trying to dupe this by setting a smaller Document to the SyntaxEditor as you said but have been unable to get the exception to occur. Could you possibly throw together a small sample project that shows this and email it over? I'd like to get this resolved for the next maint release.


Actipro Software Support

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Nevermind, I was able to dupe it reliably another way. It seems like the display lines are out of sync in this scenario and still have info for the old larger text. This is going to be a tricky one. :)


Actipro Software Support

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Got it fixed for the next maintenance release.


Actipro Software Support

Posted 17 years ago by Justin Stenning - Manager, Research & Development, netcat.biz Pty Ltd
Avatar
Great news. In the end I had to go back to using a separate editor object for each document, as there were still some cases i couldn't get around (same problem tho).

Looking forward to the release.

Cheers,
J
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.