VisualSpeller, help!

hi,

I got this from the Visualspeller demo, and I converted it to work with the lite version. But there is still a problem.
Namely if I click replace, all the text in the Richedit box disappears. I don't know what it is. Can anyone try it out. And make the necessary changes, so that the text gets changed but doesn't disappear.
Please make it clear what needs to be changed. Lots of points so ready made code is appreciated.

Before I forget, a normal Richedit is used with .Hideselection := False;

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  OleCtrls, vcspell3, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    RichEdit1: TMemo;
    Button2: TButton;
    OpenDialog1: TOpenDialog;
    VSSpell1: TVSSpell;
    procedure Spelling1Click(Sender: TObject);
    procedure VSSpell1Misspelled(Sender: TObject;
      var EventAction: Smallint);
    procedure VSSpell1Complete(Sender: TObject; var EventAction: Smallint);
    procedure VSSpell1BeforeReplace(Sender: TObject;var EventAction: Smallint);
    procedure VSSpell1AfterPopup(Sender: TObject; var EventAction: Smallint);
    procedure VSSpell1CheckStatus(Sender: TObject; var EventAction: Smallint);
    procedure VSSpell1CheckError(Sender: TObject; var EventAction: Smallint);
    procedure VSSpell1AfterReplace(Sender: TObject; var EventAction: Smallint);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Spelling1Click(Sender: TObject);
var
   size: integer;
   buffer: PChar;
begin
     RichEdit1.HideSelection := False;
          {
      Here we will use a third spellchecker control to spellcheck using the
      internal popups, but this time entirely under the control of events,
      including highlighting from within an event.

      The events that occur are:
          Misspell (Word misspellede)
          Complete (Done or canceled)
          BeforeReplace (Automatic replace about to occur)
          AfterReplace (Automatic replacement done)
          AfterPopup (Automatic popup completed)
          CheckStatus(Some status condition occurred)
          Checkerror (An error occurred)

      There is also a found event, but that is disabled by default.  It would
      fire every single found word, and just eat up time.

      NOTE:  IN ORDER FOR THE SELECTION TO BE HIGHLIGHTED WHILE A DIALOGUE
             (POPUP) IS DISPLAYED, THE HideSelection PROPERTY OF THE MEMO
             CONTROL MUST BE SET TO FALSE!
      }
      VSSpell1.ClearCounts := integer(True);
      {
       Here, the spellcheck is started via CheckText.  When control returns,
       we're done, because everything will have been handled in an event.
       Well, everything except an error firing an event.   But who
       cares!!!
      }
      size := RichEdit1.GetTextLen;
      Inc(Size);
      GetMem(Buffer, Size);
      RichEdit1.GetTextBuf(Buffer, Size);
      VSSpell1.CheckText := Buffer;
      {
       Now go look at the various events to see the behind-the-scenes code!
      }
end;

procedure TForm1.VSSpell1Misspelled(Sender: TObject; var EventAction: Smallint);
var
   buffer: Pchar;

begin
     {
      If replacements occurred, update the text so the highlighting
      offsets will be correct.  Then highlight the word that will be
      displayed in the popup box.
     }
     if VSspell1.ReplaceOccurred = True then
        begin
             Buffer := PChar(VSSpell1.Text);
             RichEdit1.SetTextBuf(Buffer);
        end;
     { Now we're sure the memo text matches that saved by the
       OCX, so we can go ahead and highlight the word in the
       textbox }
     RichEdit1.SelStart := VSSpell1.WordOffset;
     RichEdit1.SelLength := Length(VSSpell1.MisspelledWord);
     {Now exit.  The default condition will go ahead and invoke the
     automatic popup box.  We could have done the job ourself, then
     set VSSpell1.ResumeCheck to continue the spellchecking,
     or cancelled the spellcheck.}

end;

procedure TForm1.VSSpell1Complete(Sender: TObject;var EventAction: Smallint);
var
   buffer: PChar;
   msg: string;
begin
     {
      Two things can get us here - completion (result code of 0)
      or cancel
     }
     if VSSpell1.ResultCode = 0 then
        begin
             msg := 'Spellcheck complete' + Chr(10);
             msg := msg + IntToStr(VSSpell1.WordCount) + ' words Checked' + Chr(10);
             msg := msg + IntToStr(VSSpell1.ReplaceCount) + ' Words Replaced';
        end
     else
         msg := 'SpellCheck Cancelled!';
     MessageDlg(msg, mtInformation, [mbOK], 0);
     { In either case, update the text box if replaces occurred.}
     if VSspell1.ReplaceOccurred = True then
        begin
             Buffer := PChar(VSSpell1.Text);
             RichEdit1.SetTextBuf(Buffer);
        end;

end;

procedure TForm1.VSSpell1BeforeReplace(Sender: TObject; var EventAction: Smallint);
begin
     {
      This indicates a global replace is about to be made, but
      there is no sense in doing anything. Just let it happen!!
     }
end;

procedure TForm1.VSSpell1AfterPopup(Sender: TObject; var EventAction: Smallint);
var
   Buffer: PChar;
begin
     {
      An automatic popup session has completed.  If a replacement was
      made, update the text control.
      }
      if VSspell1.ReplaceOccurred = True then
        begin
             Buffer := PChar(VSSpell1.Text);
             RichEdit1.SetTextBuf(Buffer);
        end;
end;

procedure TForm1.VSSpell1CheckStatus(Sender: TObject; var EventAction: Smallint);
begin
     { BreakWordCount has expired and we should give others a
       time slice by calling ProcessMessages.  Then, we just exit
       and spellchecking will pick back up.
     }
     Application.ProcessMessages;
end;

procedure TForm1.VSSpell1CheckError(Sender: TObject; var EventAction: Smallint);
begin
     {
      An error condition has occurred.  Let's just use the
      internal error popup.
     }
     VSSpell1.PopUpError := 1;
end;

procedure TForm1.VSSpell1AfterReplace(Sender: TObject; var EventAction: Smallint);
var
   Buffer: PChar;
begin
     {
      A global replace has been made.  If we wanted to, now would be
      an opportunity to update the text in the memo box.  However, that
      would only slow things down, and we do it when we need to anyways.

      To try, just uncomment the following lines of code:
      }
      {Buffer := PChar(VSSpell1.Text);
      RichEdit1.SetTextBuf(Buffer);}
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
Form1.OpenDialog1.Options := [ofFileMustExist];
     if Form1.OpenDialog1.Execute then
        RichEdit1.Lines.LoadFromfile(Form1.OpenDialog1.Filename);
end;

end.
degraefAsked:
Who is Participating?
 
MatveyConnect With a Mentor Commented:
Hi. I'm glad to tell you that I found the bug. It's about different sypes of strings used with ActiveXes and Delphi.

Update all occurences of

if VSspell1.ReplaceOccurred = True then
  begin
       Buffer := PChar(VSSpell1.Text);
       RichEdit1.SetTextBuf(Buffer);
  end;

With

  if VSspell1.ReplaceOccurred = True then
  begin
    t := VSSpell1.Text;
    RichEdit1.SetTextBuf(PChar(t));
  end;

-Where t: AnsiString;

-This should do it.

-Thanks for the link - will get handy some day.

Hope this really fixes the bug - I tested it quite a lot, and it seems to be the only problem with this code.

c u, Matvey
0
 
MatveyCommented:
Hi. I don't know about this demo - where did you get it?

PS "RichEdit1: TMemo", you said it's a TRichEdit...
0
 
degraefAuthor Commented:
I tried both, but when it didn't work I tried a Tmemo, for convenience I renamed it RichEdit1, so I didn't have to change the code, same result in both, the text dissapears.

ftp://ftp.visualcomp.com/techsupport/visualspeller/Delphi/spdelph.zip

bye
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
degraefAuthor Commented:
Thanks, it works. Perfect

btw, if you go to www.visualcomp.com and go to the visualspeller pages, you can download extra dictionaries, and a compiler to make your own dictionaries. Very good.
0
 
MatveyCommented:
-Thanks, I'll check it out.

Glad it works, and sorry such small question took you so much points.
c u, Matvey
0
 
MatveyCommented:
BTW, just viewed your info, and found that you had a question abtout macros. I hope you got a good answere on it. Right now I'm developing a macro component. The first beta release is available already, though it's rather limited. You check it out, post your email, and I'll tell you when the official, new, cool version appears (if you still need it of course).

bosism@netvision.net.il

http://www.delphipages.com/edit/count.cfm?comID=453&Link=uploads%2FMiscellaneous%2FMUMacro1%2Ezip
0
 
degraefAuthor Commented:
always interested e-mail = bs130956@skynet.be
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.