LiveSpelling problem

General TRichView support forum. Please post your questions here
Post Reply
Serge Perepel
Posts: 7
Joined: Mon Feb 04, 2008 6:51 pm

LiveSpelling problem

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

Post by Sergey Tkachenko »

Can you send me a simple project reproducing this bug?
Pieter E.
Posts: 835
Joined: Sun Aug 28, 2005 9:34 am

Post by Pieter E. »

You should close/stop the Live Spellchecker before closing. I had the same problems a long time ago.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Serge Perepel
Posts: 7
Joined: Mon Feb 04, 2008 6:51 pm

Post by Serge Perepel »

I'll try to get little project together. Thank you for quick response.
Serge Perepel
Posts: 7
Joined: Mon Feb 04, 2008 6:51 pm

Post by Serge Perepel »

How do you close live spell checker? I just call clear.
Serge Perepel
Posts: 7
Joined: Mon Feb 04, 2008 6:51 pm

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

Post 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.
Serge Perepel
Posts: 7
Joined: Mon Feb 04, 2008 6:51 pm

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

Post 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.
Serge Perepel
Posts: 7
Joined: Mon Feb 04, 2008 6:51 pm

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

Post 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.
Serge Perepel
Posts: 7
Joined: Mon Feb 04, 2008 6:51 pm

Post 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
duzenko
Posts: 9
Joined: Thu Feb 07, 2008 3:20 pm

Post by duzenko »

Once I got somewhat related to that. I used ClearLiveSpellingResults to force the live spelling to terminate.
Post Reply