summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/aspell/examples/example.pas
blob: 8f5221bda29b3e5da811ad924ed4a271ebbca2c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
program Example;

{$mode objfpc}{$H+}

uses
  SpellCheck;

var
  i, j: Integer;
  s: TSuggestionArray; { in case the word is wrong, this array contains
                         a list of suggestions }
  Speller: TWordSpeller;
begin
  if Paramcount < 2 then // check if user has used valid input
    Writeln('Usage: ', ParamStr(0), ' <lang> <word1> <word2> ...')
  else begin
    Speller := TWordSpeller.Create;
    Speller.Language := ParamStr(1);

    for i := 2 to ParamCount do begin // go for each word specified
      s := Speller.SpellCheck(ParamStr(i)); // spellcheck each word
      if Length(s) > 0 then begin // we need to write suggestions
        Write(ParamStr(i), ' is wrong. Here are some suggestions: ');
        for j := 0 to High(s) do
          Write(s[j], ' '); // write out the suggestions
        Writeln; // to keep format
      end else
        Writeln(ParamStr(i), ' is spelled correctly!');
    end;

    Speller.Free;
  end;
end.