Strange problem

General TRichView support forum. Please post your questions here
Post Reply
VoodooMike
Posts: 5
Joined: Sun Jan 15, 2006 9:50 am
Contact:

Strange problem

Post by VoodooMike »

I use TRichView for text entry in my chat software. Recently I decided I would alter the software such that it would support unicode. I ran into a strange problem.

The program uses multiple docked forms, as tabs, each with its own richview and richviewedit for sending and recieving. The OnShow event of the form creates the initial tabs (saved from last session) and then various other events during program execution may create others.

The problem is this - the tabs which are created initially have a problem with any initial typing you do within them. If you begin typing in one, the letters come out in strange order, the cursor is misplaced, and so on. If, in the creation routine, I do an AddTextNLW with some text, it shows that text as it would if unicode was not enabled... with the little blocks between each letter, despite all styles having unicode enabled. If, after it starts doing its strange typing mistakes or whatever.... I backspace the gibberish gone, or select all and delete it, then when I type it works properly.

If the tabs are created after that initial setup, the richviewedit works perfectly right from the start.

Indeed, if spellchecking is set to rvlspOnChange, there is an exception raised because the text being entered is only 1 character wide... which implies that for some reason, the tabs created at startup are losing a single character for reasons I just can't comprehend...

All styles are set to unicode, and are using the Arial Unicode MS font .. the program is massively too big (and containing commercial code) for me to paste it for people to weed through. Any ideas on where to start with this?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Try to call RichViewEdit.Clear after changing Unicode properties of text styles.
Initially, TRichViewEdit may have one empty text item. If you do not delete it when changing Unicode properties, it is still marked as not Unicode while linked to Unicode text style, so the problem happens.
VoodooMike
Posts: 5
Joined: Sun Jan 15, 2006 9:50 am
Contact:

Post by VoodooMike »

The unicode styles are set at design-time. What you're saying sounds like it would be right - there being a single non-unicode text item in place that is treated as the first half of a unicode text item. However I tried the following:

- calling .clear after the form is created.
- having it add text, highlight, and delete it.

If the second part is done manually, it then begins to work. However it does not work if done automatically at runtime.

Indeed, if I use AddTextNLW to add a unicode string, it displays the string with the squares between it, as it would if you added a unicode string to a non unicode control. It looks as though the TRichViewEdit is not initially unicode enabled until after typing happens.... but only for the forms created initially when the program is executed (during the main form's OnShow event). If the forms are created later, it works as it is supposed to.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Is it possible to create a project reproducing the problem and send it to me?
You can use this code to detect error. It checks if the RichViewEdit1 content's Unicode mode corresponds to TextStyles[].Unicode.
Only the first item is checked.

Code: Select all

 
uses RVItem;

 RichViewEdit1.Format;
  if (RichViewEdit1.GetItemStyle(0)>=0) then
    if RichViewEdit1.Style.TextStyles[RichViewEdit1.GetItemStyle(0)].Unicode<>
       (rvioUnicode in RichViewEdit1.GetItem(0).ItemOptions) then
    Application.MessageBox('Unicode mismatch!', nil)
It's very strange that you said about AddTextNLW. It looks like Unicode property of style is changed AFTER calling AddTextNLW, because it always adds string correctly.
VoodooMike
Posts: 5
Joined: Sun Jan 15, 2006 9:50 am
Contact:

Post by VoodooMike »

The code snippet you posted, added to the initial creation, does not trigger the application message.

The frustrating part of this is the inconsistant behavior in the program. Only the forms created during startup are affected, and it goes away if you backspace after typing some, or clear things out manually. The exact same form created during runtime, not at program execution, work properly right from the get-go!

I'll try to duplicate the problem in a stand-alone program if possible. Thanks for the help :)
Post Reply