RichEdit Aktif Kelimeyi Bulma ?
Forum kuralları
Forum kurallarını okuyup, uyunuz!
Forum kurallarını okuyup, uyunuz!
RichEdit Aktif Kelimeyi Bulma ?
...
En son burak_489 tarafından 12 Mar 2011 12:52 tarihinde düzenlendi, toplamda 1 kere düzenlendi.
Re: RichEdit Aktif Kelimeyi Bulma ?
Kod: Tümünü seç
// uses math;
Function GetWord( ALine : AnsiString; From : LongInt): AnsiString;
function GetNearest: LongInt;
var
r,l : LongInt;
begin
r:= From; l := r;
while (l>=1) and (ALine[Max(l,1)]=' ') do
Dec(l);
while (r<=Length(ALine)) and (ALine[Min(r,Length(ALine))]=' ') do
Inc(r);
if Abs(From-l)<Abs(r-From) then result := l else result :=r;
Result := Max(Min(Length(ALine),Result),1);
end;
var
sp,l,r : LongInt;
Begin
Result := '';
if (Trim(ALine)<>'') and (From <=Length(ALine)) then
Begin
if ALine[From]<>' '
then
sp := Min(From,Length(ALine)-1)
else
sp := GetNearest;
l := sp;
r := sp;
while (l>=1) and (ALine[Max(l,1)]=' ') do Dec(l);
while (r<=Length(ALine)) and (ALine[Min(r,Length(ALine))]=' ') do Inc(r);
Result := '';
while (l>=1) and (ALine[Max(l,1)]<>' ') do
Begin
if l<>r then Result := ALine[l] +Result;
Dec(l);
end;
while (r<=Length(ALine)) and (ALine[Min(r,Length(ALine))]<>' ') do
Begin
Result := Result+ ALine[r];
Inc(r);
end;
Result := Trim(Result);
end;
End;
Kod: Tümünü seç
procedure TForm1.RichEdit1SelectionChange(Sender: TObject);
Var
line: String;
Nokta: TPoint;
begin
Nokta:=(Sender As TRichEdit).CaretPos;
line:=(Sender As TRichEdit).Lines.Strings[Nokta.Y];
Caption := Format('Word:"%s" X:%d Y:%d Length:%d',[GetWord(line,Nokta.X),Nokta.X,Nokta.Y,Length(line)]);
end;