Calling GetStyleCodePage in OnSpellingCheck event

General TRichView support forum. Please post your questions here
Post Reply
vit
Posts: 115
Joined: Tue Feb 03, 2009 3:11 pm

Calling GetStyleCodePage in OnSpellingCheck event

Post 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!
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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?
vit
Posts: 115
Joined: Tue Feb 03, 2009 3:11 pm

Post 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)?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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).
vit
Posts: 115
Joined: Tue Feb 03, 2009 3:11 pm

Post by vit »

Thank you! I will try
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Thread without synchronize

Post 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 ;-)
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, this event is not synchronized intentionally. It is supposed that it is called in a thread.
Post Reply