RichEdit Aktif Kelimeyi Bulma ?

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Kullanıcı avatarı
burak_489
Üye
Mesajlar: 31
Kayıt: 20 Ara 2010 09:20

RichEdit Aktif Kelimeyi Bulma ?

Mesaj gönderen burak_489 »

...
En son burak_489 tarafından 12 Mar 2011 12:52 tarihinde düzenlendi, toplamda 1 kere düzenlendi.
Kullanıcı avatarı
Lost Soul
Üye
Mesajlar: 1064
Kayıt: 01 Nis 2007 02:55
Konum: mekan ANKARA toprak ELAZIĞ
İletişim:

Re: RichEdit Aktif Kelimeyi Bulma ?

Mesaj gönderen Lost Soul »

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;

Cevapla