Page 1 of 1

LiveSpelling problem

Posted: Wed Feb 20, 2008 4:03 pm
by Serge Perepel
Hi Sergey,

I have a problem with StartLiveSpelling. If I use this function, then when ever I close my MDI editor window it has a chance of crashing the whole application. I figured that if I rem out that line it would never crash. I don't even type anything in, just quickly open and close MDI window with editor in it. Please let me know if there is anything I'm doing wrong.

Posted: Wed Feb 20, 2008 4:46 pm
by Sergey Tkachenko
Can you send me a simple project reproducing this bug?

Posted: Wed Feb 20, 2008 6:06 pm
by Pieter E.
You should close/stop the Live Spellchecker before closing. I had the same problems a long time ago.

Posted: Wed Feb 20, 2008 6:30 pm
by Sergey Tkachenko
In the next update I fixed some possible issues with live spelling on closing. The fix was oriented on db components, but probably this is the same problem.
I will upload this update as soon as Ilya finish testing new version of ScaleRichView.

Posted: Wed Feb 20, 2008 6:47 pm
by Serge Perepel
I'll try to get little project together. Thank you for quick response.

Posted: Wed Feb 20, 2008 6:54 pm
by Serge Perepel
How do you close live spell checker? I just call clear.

Posted: Wed Feb 20, 2008 9:15 pm
by Serge Perepel
Hi Sergey,

I fixed my problem by changing RVThread unit.

Here is original code:

Code: Select all

{------------------------------------------------------------------------------}
{ Waits while finishing processing the current item and closes the thread.
  Context: main process (caller) }
procedure TRVWordEnumThread.Finish;
{$IFNDEF RICHVIEWDEF6}
var Msg: TMsg;
{$ENDIF}
begin
  if StopWorking=3 then
    exit;
  StopWorking := 1;
  Priority := tpNormal;
  while (StopWorking=1) and not Suspended do
    {$IFDEF RICHVIEWDEF6}CheckSynchronize;{$ELSE}
    if PeekMessage(Msg, 0, $8FFF, $8FFF, PM_REMOVE) then
        TranslateMessage(Msg);
    {$ENDIF};
  if Suspended then
    Resume;
  Terminate;
end;
And here is my change:

Code: Select all

{------------------------------------------------------------------------------}
{ Waits while finishing processing the current item and closes the thread.
  Context: main process (caller) }
procedure TRVWordEnumThread.Finish;
{$IFNDEF RICHVIEWDEF6}
var Msg: TMsg;
{$ENDIF}
begin
  if StopWorking=3 then
    exit;
  StopWorking := 1;
  Priority := tpNormal;
  if Suspended then [color=orange]//I resumed since StopWorking can't change when suspended[/color]
    Resume;
  while (StopWorking=1) and not Suspended do [color=orange]//Wait till StopWorking turns 2[/color]
    {$IFDEF RICHVIEWDEF6}CheckSynchronize;{$ELSE}
    if PeekMessage(Msg, 0, $8FFF, $8FFF, PM_REMOVE) then
        TranslateMessage(Msg);
    {$ENDIF};
  Terminate; [color=orange]//Safe to terminate[/color]
  while (StopWorking<>3) and not Suspended do      [color=orange]//Wait till StopWorking turns 3[/color]
    {$IFDEF RICHVIEWDEF6}CheckSynchronize;{$ELSE}  [color=orange]//So it won't get out of dll too early [/color]
    if PeekMessage(Msg, 0, $8FFF, $8FFF, PM_REMOVE) then
        TranslateMessage(Msg);
    {$ENDIF};
end;
Please let me know if what I did is not apropriate.

Posted: Thu Feb 21, 2008 2:32 pm
by Sergey Tkachenko
Hmm. The purpose of this procedure is wating while spellchecking of the next word is complete. If the thread is suspended, there are no reasons to wait for it. The cycle "while (StopWorking=1) and not Suspended do" is not executed if Suspended=True. So my code resumes the suspended thread immediately before calling Terminate.
Probably it would be better to call Terminate before Resume...
Yes, in my code Finish may exit before the thread is terminated, but I do not see a problem here.

Posted: Thu Feb 21, 2008 3:02 pm
by Serge Perepel
Maybe thats the whole issue - the thread exiting function before it is out of execute. I have special case in using your control. I have it in DLL that is loaded dynamically every time I open MDI and unloaded when I close it. So, the thread being in execute and me unloading DLL might cause the problem. Please, let me know if it makes any sense.

Posted: Thu Feb 21, 2008 3:17 pm
by Sergey Tkachenko
I am not sure...
But I am afraid that the second cycle may be dangerous, because the thread may finish after calling Terminate, and since FreeOnTerminate is True, it will be destroyed, possibly while executing this cycle.

Posted: Thu Feb 21, 2008 3:30 pm
by Serge Perepel
Maybe after terminate it needs simple sleep(10) loop and check on StopWorking. Or maybe I need somehow to check on StopWorking in my code and not to unload DLL until it is out of execute.

Posted: Thu Feb 21, 2008 3:44 pm
by Sergey Tkachenko
Well, actually this cycle is not so dangerous, if think the possibility of error is almost zero.
But I will not add it in my version, you can leave it in yours.

Posted: Thu Feb 21, 2008 3:54 pm
by Serge Perepel
Sergey,

Thank you for your help. I think not a lot of users would have the same situation. The only think I'm concerned is that I will have to change any version I download. I guess I'll have to remember.

P.S.

I love this control, awesome work :D

Posted: Tue Mar 04, 2008 10:55 am
by duzenko
Once I got somewhat related to that. I used ClearLiveSpellingResults to force the live spelling to terminate.