Page 1 of 1

Calling GetStyleCodePage in OnSpellingCheck event

Posted: Fri Dec 25, 2009 2:34 pm
by vit
Hi!

I call RVE.RVData.GetStyleCodePage in OnSpellingCheck event handler.
Is it safe?

If I understand right, OnSpellingCheck handlers calling without synchronization.

I have an exception with next stacktrace:

Code: Select all

System                             @AsClass
RVStyle                            TFontInfos.GetInvalidItem
RVStyle                            TFontInfos.GetItem
CRVData                            TCustomRVData.GetStyleCodePage
MedStSpellChecking                 TSpellChecker.GetUnicode
MedStSpellChecking                 TSpellChecker.IsMisspelled
MedStCustomTextParamContentClasses TCustomTextInplaceEditor._OnSpellCheck
TCustomTextInplaceEditor - is TRichViewEdit descendant, _OnSpellCheck - his OnSpellingCheck event handler.

Can be the problem in multi access violation?

Thanks!

Posted: Sat Dec 26, 2009 6:14 pm
by Sergey Tkachenko
Yes, this event is called in a thread context.
I am not sure about the reason of this error, but since TFontInfos.GetInvalidItem is in the stack, this means that GetStyleCodePage is called for invalid StyleNo (negative or >= RVStyle.TextStyles.Count).
Can you check why may it happen?

Posted: Mon Dec 28, 2009 8:27 am
by vit
It is pretty rare exception. I can't repeat this (the error report was sended by our program from one of our customer).

Is there possible say GetStyleCodePage (from thread context) try to access to RVStyle.TextStyles and at the same time RVE change (in main thread context) this value (because user was change text)?

Posted: Tue Dec 29, 2009 10:09 am
by Sergey Tkachenko
It must not happen when you use standard editing operation: they wait while the thread finishes checking a word. The same for Clear method.
However, if you have your own operations that are not started from Clear and use non-editing methods, you should be careful (call ClearLiveSpellingResults before them).

Posted: Tue Dec 29, 2009 12:50 pm
by vit
Thank you! I will try

Thread without synchronize

Posted: Sun Jan 05, 2014 9:01 pm
by Jim Knopf
Hi,

had problems with OnSpellingCheck:

Code: Select all

original method:
  Misspelled := not RVHunSpell1.Spell(GetUnicode(AWord, StyleNo));
I had to expand the method for a check if the word is to be found in a 'project dictionary'.

Code: Select all

  Misspelled := not RVHunSpell1.Spell(GetUnicode(AWord, StyleNo));
  if Misspelled then
    Misspelled := lbProjectDic.Items.IndexOf(AWord) = -1;
from this moment I had som funny ghost train hours because the problem didn't occur always (and not on each pc!) and I didn't know that it the cause of troubles was this routine.

It took nearly one day to find out that the problem of the non-functioning program was this method. Reason: OnSpellingCheck should be synchroniced from component TRichViewEdit!

Solution (better: work around) with all ascessory for critical section:

Code: Select all

  Misspelled := not RVHunSpell1.Spell(GetUnicode(AWord, StyleNo));
  if Misspelled then
  try
    EnterCriticalSection(FCS);
    Misspelled := FProjectDic.IndexOf(AWord) = -1;
  finally
    LeaveCriticalSection(FCS);
  end;
Would be fine for the future, if the method is synchronized by TRichViewEdit by Synchronize (Method: TThreadMethod); of thread object. So developers will have less problems with next version ;-)

Posted: Mon Jan 06, 2014 8:20 am
by Sergey Tkachenko
Sorry, this event is not synchronized intentionally. It is supposed that it is called in a thread.