Solved

VisualSpeller, help!

Posted on 1998-08-02
7
475 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:degraef
  • 4
  • 3
7 Comments
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
Hi. I don't know about this demo - where did you get it?

PS "RichEdit1: TMemo", you said it's a TRichEdit...
0
 

Author Comment

by:degraef
Comment Utility
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
 
LVL 3

Accepted Solution

by:
Matvey earned 300 total points
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:degraef
Comment Utility
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
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
-Thanks, I'll check it out.

Glad it works, and sorry such small question took you so much points.
c u, Matvey
0
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
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
 

Author Comment

by:degraef
Comment Utility
always interested e-mail = bs130956@skynet.be
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now