DynamicSyntaxLanguage

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by Ernesto Obregon
Avatar
I have upgraded to the latest version v.0.0260 and I am trying to utilize the DynamicSyntaxLanguage with my existing XML language definition file to achieve multi-line commenting using my comment character ' that is defined as my CommentDelimeterStyle - Pattern Value="'"

(1) To achieve multi-line commenting with the click of a button do I need to utilize the DynamicSyntaxLanguage class that inherits the DynamicOutliningSyntaxLanguage ?

(2) When utilizing the above class and inherited class I receive the following error when loading my XML file via:
editor.Document.LoadLanguageFromXml(LanguagePath, 0)
The error is:
An error occurred while loading the DynamicSyntaxLanguage '{Unknown}':
An instance of the syntax language type 'MyEditor.MyEditorDynamicLanguage, MyEditor' could not be created. Please ensure that a public constructor exists with the same parameters as the base 'DynamicSyntaxLanguage' class. The problem that occurred was:
Cannot create and abstract class.
The problem occurred near line 3, position 2
in Unknown Stream.

Where does this other constructor go ? My DynamicSyntaxLanguage class has the following constructor for a new instance:
Public Sub New(ByVal key as String, ByVal secure As Boolean)
MyBase.New(Key, Secure)
End Sub
Thanks

Comments (4)

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

The best thing to do is look at the samples in the Languages/Dynamic folder. They show how to do a lot of these things and are pretty good code examples.

1) For this you need to add this to your code-behind class:
''' <summary>
''' Resets the <see cref="SyntaxLanguage.LineCommentDelimiter"/> property to its default value.
''' </summary>
Public Overloads Overrides Sub ResetLineCommentDelimiter()
    Me.LineCommentDelimiter = "'"
End Sub
''' <summary>
''' Indicates whether the <see cref="SyntaxLanguage.LineCommentDelimiter"/> property should be persisted.
''' </summary>
''' <returns>
''' <c>true</c> if the property value has changed from its default; otherwise, <c>false</c>.
''' </returns>
Public Overloads Overrides Function ShouldSerializeLineCommentDelimiter() As Boolean
    Return (Me.LineCommentDelimiter <> "'")
End Function
2) For this one, make sure you have a non-abstract class named "MyEditor.MyEditorDynamicLanguage" in "MyEditor" assembly that has constructors like this:
''' <summary>
''' This constructor is for designer use only and should never be called by your code.
''' </summary>
Public Sub New()
End Sub    'New

''' <summary>
''' Initializes a new instance of the <c>CSharpDynamicSyntaxLanguage</c> class. 
''' </summary>
''' <param name="key">The key of the language.</param>
''' <param name="secure">Whether the language is secure.</param>
Public Sub New(ByVal key As String, ByVal secure As Boolean)
    MyBase.New(key, secure)
End Sub    'New


Actipro Software Support

Posted 17 years ago by Ernesto Obregon
Avatar
Thanks for the reply. This is what I have in my MyEditorDynamicLanguage.vb
Do I need another class too?

Imports System
Imports ActiproSoftware.SyntaxEditor
Imports ActiproSoftware.SyntaxEditor.Addons.Dynamic

Public MustInherit Class MyEditorDynamicLanguage
    Inherits DynamicOutliningSyntaxLanguage

    Public Sub New()
    End Sub

    Public Sub New(ByVal key As String, ByVal secure As Boolean)
        MyBase.New(Key, Secure)
    End Sub

    ''' <summary>
    ''' Resets the <see cref="SyntaxLanguage.LineCommentDelimiter"/> property to its default value.
    ''' </summary>
    Public Overloads Overrides Sub ResetLineCommentDelimiter()
        Me.LineCommentDelimiter = "'"

    End Sub
    ''' <summary>
    ''' Indicates whether the <see cref="SyntaxLanguage.LineCommentDelimiter"/> property should be persisted.
    ''' </summary>
    ''' <returns>
    ''' <c>true</c> if the property value has changed from its default; otherwise, <c>false</c>.
    ''' </returns>
    Public Overloads Overrides Function ShouldSerializeLineCommentDelimiter() As Boolean
        Return (Me.LineCommentDelimiter <> "'")
    End Function

End Class

I did get this from the TestApplication-VB.NET20 sample, except I had to add the MustInherit statement because I received an error about that it must inherit or override the following Inherited 'MustOveride' member(s), so I added MustInherit.


When I received the original error about the constructor I then searched the TestApplication to see if it had another class with an identical constructor, but this is where I got lost because I did not find one.

Thanks

[Modified at 09/25/2007 06:00 PM]
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Ernesto,

Yes the MustInherit you added is causing the error you previously mentioned since SyntaxEditor can't create an instance of your code-behind class.

You probably need to implement a stub GetTokenOutliningAction since you are inheriting DynamicOutliningSyntaxLanguage. I believe you can leave that method empty as long as you implement it.

But if you make those changes then it should work.


Actipro Software Support

Posted 17 years ago by Ernesto Obregon
Avatar
Sweet, that did it

Thank you
Ernesto

[Modified at 09/26/2007 11:05 AM]
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.