procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var s:string;i,position,len:integer;
begin
if key=46 then
begin
s:='';
Position:=memo1.SelStart;
len:=Memo1.SelLength;
memo1.SelStart:=Memo1.SelStart-1;
memo1.SelLength:=1;
//取光标所在位置前半段单词
while (memo1.SelText[1] in ['a'..'z','A'..'Z','-']) and (memo1.SelStart>0) do
begin
s:=memo1.SelText+s;
memo1.SelStart:=Memo1.SelStart-1;
memo1.SelLength:=1;
end;
memo1.SelStart:=Position;
memo1.SelLength:=1;
//取光标所在位置后半段单词
while memo1.SelText[1] in ['a'..'z','A'..'Z','-'] do
begin
s:=s+memo1.SelText;
memo1.SelStart:=Memo1.SelStart+1;
memo1.SelLength:=1;
end;
//复原
memo1.SelStart:=Position;
memo1.SelLength:=len;
//判断是否关键词,可自己修改
if ListBox1.Items.IndexOf(LowerCase(s))>-1 then key:=0;
end;
end;