[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VisualSpeller, help!

Posted on 1998-08-02
7
Medium Priority
?
511 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1200 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 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