Solved

VisualSpeller, help!

Posted on 1998-08-02
7
481 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
ID: 1359495
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
ID: 1359496
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
ID: 1359497
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:degraef
ID: 1359498
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
ID: 1359499
-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
ID: 1359500
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
ID: 1359501
always interested e-mail = bs130956@skynet.be
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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