: Hello,
:
: I am making a spell checker and a beginner in Delphi.
:
: Well, I have 2 forms - Form1 has a MemoBox, and 3 buttons (Open
: File, Check File and Save File). When I click on Open file, the
: selected file is loaded in MemoBox and when I click on check file.
: It should start checking for spelling checks. and saving a
: file..shud save the file. In my Form 2, I have 2 edit boxes for 'Not
: in dictionary' and 'replace with' and 2 buttons 'Ignore' and
: 'Change'.
:
: Now I am stuck with 'Check file' code in Form 1. As soon as click on
: this button, the cursor should go to MemoBox. and it should start
: checking word by word from my 'list_of_words.text'. In case it found
: or not , Form 2 shoudl show up.
:
: I am not able to write code for this.
: I have just written this and dont know how to proceed. Pls suggest.
:
: procedure TForm1.BitBtn3Click(Sender: TObject);
: var
: Txt:string;
: StartPos, TxtLen, FoundPos:integer;
: begin
: try
: While not EOF(MemoBox.text) do
: begin
: StartPos:=MemoBox.SelStart+MemoBox.SelLength
:
: //I think it will go char by char and as soon as it will find a
: space '', it will treat it as a word and then look up in the
: 'list_of_words.text' file.
:
: Regards
: Pooja
:
:
EOF (End-Of-File) cannot be used in this fashion, since MemoBox.Text isn't a file.
I would use a different way of grabbing the words: stripping the text itself:
1) Copy the text into a string variable
2) Remove any punctuation/double spaces/tabs from the text, so that you only have words and spaces
3) Grab the first word, and remove it from the text
WordToCheck := Copy(TheText, 1, Pos(' ', TheText)-1);
Delete(TheText, 1, Pos(' ', TheText));
[/cdoe]
4) Check the word against your dictionary.
4a) If you want to replace the word, use the StringReplace() function on the original text.
4b) If you want to add the word to the dictionary or ignore the word, do nothing with the original text
Repeat steps 3 and 4 until all words are checked.
There are other (and better) ways of performing this kind of function, but this is quite easy to create.