This message contains graphics. If you do not see the graphics: Graphic Version.
TX Tops Top 10, Syntax Highlighting Revisited

how are you coming on with the TX Text Control Class Library?

The new version of TX Text Control with support for Microsoft Visual C++ has been out for several weeks now. There is the announcement article.

We would love to know how you are coming on with the new VCC+ support offered by TX Text Control. How do you find the documentation?

We would really love to hear your comments. If you have got a few moments, why not hit the REPLY button and let us know your thoughts - it'll only take you a few moments.

Thank you in advance. We are really looking forward to hearing from you.

TX Tops Top 10 at Component Source

In this week's best-seller list published by Component Source, TX Text Control is at place number 8. See for yourself.

This makes it by far the best-selling text component resold by Component Source.

Confusion About Service Pack #3 Clarified

On reviewing the support questions from last week, it became apparent that there are certain misconceptions about Service Pack #3. Please allow me to clear a few issues.

  1. Service Pack #3 contains all previous service packs.
  2. Service Pack #3 can only be installed if you are using a version of TX Text Control between v7.00 and v7.02.
  3. If you have just bought the newest version of TX Text Control, then you cannot install this Service Pack as you already have the latest version.
  4. The trial version of TX Text Control cannot be updated with any Service Pack.

Top TX Tip: Syntax Highlighting Revisited

Back in Syntax article we started a discussion on syntax highlighting and how you can use TX Text Control to construct a simple programming editor which highlights the keywords of your chosen language (be it VB, HTML or C++). If you missed this article, you can read everything you need to know in the Newsletter Archive

However, version one of our little program only allowed the keywords to be highlighted in one go, once the text had been entered. Naturally, this sucks. So, enter version two. This time we are going to change the color of all entered word on-the-fly and so fast that the user only notices the change of color and nothing else.

To keep our little program running as fast as possible, we are only going to check the last and the second to last word.

This is necessary as the user could split a keyword with a space. For example: it is quite possible that a user splits the keyword <html> into to two, thus <ht ml>.

In this case, both the '<ht' and the 'ml>' must be returned to their neutral color. In other words, the highlighting which was applied to the keyword '<html>' must be again removed.

"Sounds good, but exactly how do I go about coding this?" is probably what is running through your mind right now.

Take a look at this Visual Basic:

' When a key is pressed in the TX window, this function determines ' the last and the next word and checks if these are keywords. ' If so, they are colored accordingly... ' Public Function CheckEditedText() Dim nOldSelStart As Integer, nOldSelLength As Integer Dim nPos As Integer, nLen As Integer Dim szTmp As String Dim index As Integer With Form1.TXTextControl1 ' Turn off the wait cursor SendMessage .hwnd, TX_SETMODEEX, TF_NOWAITCURSOR, 0 ' Lock TX window update LockWindowUpdate .hwnd ' Store current selection nOldSelStart = .SelStart nOldSelLength = .SelLength szTmp = .Text ' First find the last word from the current position nPos = LastDelimiter(szTmp, nOldSelStart - 1) nLen = NextDelimiter(szTmp, nOldSelStart - 1) - nPos If (nLen > 0) Then index = IsKeyWord(Mid(szTmp, nPos + 1, nLen)) If index <> -1 Then .SelStart = nPos .SelLength = nLen .ForeColor = Colors(index) Else .SelStart = nPos .SelLength = nLen .ForeColor = vbBlack End If End If ' Now find the next word from the current position nPos = LastDelimiter(szTmp, nOldSelStart) nLen = NextDelimiter(szTmp, nOldSelStart) - nPos If (nLen > 0) Then index = IsKeyWord(Mid(szTmp, nPos + 1, nLen)) If index <> -1 Then .SelStart = nPos .SelLength = nLen .ForeColor = Colors(index) Else .SelStart = nPos .SelLength = nLen .ForeColor = vbBlack End If End If ' Set back the stored values .SelStart = nOldSelStart .SelLength = nOldSelLength .ForeColor = RGB(0, 0, 0) LockWindowUpdate 0 ' Turn on wait cursor SendMessage .hwnd, TX_SETMODEEX, TF_WAITCURSOR, 0 End With End Function

Everything is the same as in the function that checks the entire document.

The only difference is that we look for the last word before the current Cursorposition and check whether it is a keyword or not. Should it be a keyword, then we color it appropriately, otherwise we simply set the color to its default. We then move on to the next word and repeat the procedure again. However, when is this function actually called? Theoretically, whenever something is changed in the document.

But should the call to CheckEditedText be directly in the TXTextControl1_Change() event handler we would be in a situation of a never-ending look, as the document is changed in the Change handler. Not good.

Because of this we have inserted a Drity-Flag which is set to true as soon as the document is changed. This flag is looked up in the KeyUp handler. Should it be set, the function CheckEditedText is called.

Solving the dilemma in this way, we do not have to check which key is currently pressed. Should the user then press the cursor keys to scroll through the document, no Change notification will be called. And thus nothing happens in the Key handler.

As you have probably noticed, copy and paste operations have not been added to this example. We shall leave that to you, as it should not be too difficult. Naturally, you should take care to check the pasted text and highlight the inserted keywords accordingly.

Best regards

The Newsletter Team

Text Control GmbH respects your online time and privacy. We only send this newsletter to TX Text Control customers and people who have signed up to receive it. However, if you would prefer not to receive future issues of the newsletter, you may unsubscribe at any time. If you received this newsletter forwarded from a colleague or friend, you may wish to subscribe directly.

Sent to: N/A.

Imprint | Unsubscribe | Subscribe

© 2020 Text Control GmbH. All Rights Reserved.