unit UnitE2C;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure Memo1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
function IsSeparetor(ch:char):boolean;
function GetWord(pos:word):string;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
function TForm1.GetWord(pos: word): string;
var
st:string;
pos1,pos2:word;
i:longint;
w:string;
begin
w:='';
pos1:=1;
getword:='';
st:=Memo1.lines.Text;
pos2:=length(st);
for i:=pos-1 downto 1 do
if IsSeparetor(st) then
begin
pos1:=i+1;
break
end;
for i:=pos to pos2 do
if IsSeparetor(st) then
begin
pos2:=i-1;
break;
end;
if pos1<=pos2 then
begin
for i:=pos1 to pos2 do
w:=w+st;
GetWord:='单词'+w;
end;
end;
function TForm1.IsSeparetor(ch: char): boolean;
begin
IsSeparetor:=false;
if ch in [' ',',','.','?',#10,#13] then
IsSeparetor:=true
end;
procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
lc:longint;
CharPos:word;
begin
lc:=SendMessage(Memo1.Handle,EM_CHARFROMPOS,0,x+(y shl 16));
charpos:=word(lc);
Memo1.Hint:=GetWord(charpos);
end;
end.