var
words: TStringList;
procedure TForm1.FormCreate(Sender: TObject);
begin
words := TStringList.Create;
words.Sorted := true;
words.Add('one');
words.Add('two');
words.Add('four');
words.Add('five');
words.Add('six');
words.Add('seven');
words.Add('eight');
words.Add('nine');
words.Add('ten');
end;
procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
const
chars: set of char = ['A'..'Z', 'a'..'z', 'А'..'Я', 'а'..'я'];
var
w: string;
i: integer;
s: string;
full: string;
SelSt: integer;
begin
case Key of
VK_RETURN, VK_TAB:
begin
Edit1.SelStart := Edit1.SelStart + Edit1.SelLength;
Edit1.SelLength := 0;
Exit;
end;
VK_DELETE, VK_BACK:
begin
Edit1.ClearSelection;
Exit;
end;
end;
s := Edit1.Text;
SelSt := Edit1.SelStart;
i := SelSt;
if (length(s) > i) and (s[i+1] in chars) then
Exit;
w := '';
while (i >= 1) and (s[i] in chars) do
begin
w := s[i] + w;
dec(i);
end;
if length(w) <= 0 then
Exit;
words.Find(w, i);
if (i >= 0) and (UpperCase(copy(words[i], 1,
length(w))) = UpperCase(w)) then
begin
full := words[i];
insert(copy(full, length(w) + 1, length(full)), s, SelSt + 1);
Edit1.Text := s;
Edit1.SelStart := SelSt;
Edit1.SelLength := length(full) - length(w);
end;
end;
|