example.pas 958 B

12345678910111213141516171819202122232425262728293031323334
  1. program Example;
  2. {$mode objfpc}{$H+}
  3. uses
  4. SpellCheck;
  5. var
  6. i, j: Integer;
  7. s: TSuggestionArray; { in case the word is wrong, this array contains
  8. a list of suggestions }
  9. Speller: TWordSpeller;
  10. begin
  11. if Paramcount < 2 then // check if user has used valid input
  12. Writeln('Usage: ', ParamStr(0), ' <lang> <word1> <word2> ...')
  13. else begin
  14. Speller := TWordSpeller.Create;
  15. Speller.Language := ParamStr(1);
  16. for i := 2 to ParamCount do begin // go for each word specified
  17. s := Speller.SpellCheck(ParamStr(i)); // spellcheck each word
  18. if Length(s) > 0 then begin // we need to write suggestions
  19. Write(ParamStr(i), ' is wrong. Here are some suggestions: ');
  20. for j := 0 to High(s) do
  21. Write(s[j], ' '); // write out the suggestions
  22. Writeln; // to keep format
  23. end else
  24. Writeln(ParamStr(i), ' is spelled correctly!');
  25. end;
  26. Speller.Free;
  27. end;
  28. end.