Einzelnen Beitrag anzeigen

Benutzerbild von Lannes
Lannes

Registriert seit: 30. Jan 2005
Ort: Münster
745 Beiträge
 
Delphi 3 Professional
 
#5

Re: Wahre Position des Cursors im Memo

  Alt 16. Sep 2009, 15:06
Hallo,

also möchtest Du die Zeile im Zustand WordWrap = False.

Zitat von martinf16:
...damit lässt sich ja eine Funktion zusammenbauen ...
Da gibt es mehrere Möglichkeiten, such Dir eine aus, im Ergebnis sind alle gleich:

- Über den Zeichenindex harte Umbrüche vor und nach Selstart suchen
Delphi-Quellcode:
function GetNoWordWrapSelLinesI(aMemo: TMemo): String;
var a,e : Integer;
    s : String;
begin
  s := aMemo.Text;
  a := aMemo.SelStart;
  e := a;
  while (a >= 1) and (s[a] <> #10) do
    dec(a);
  while (e <= Length(s)) and (s[e] <> #13) do
    inc(e);
  Result := Copy(s,a +1, e - a -1);
end;
-mit EM_LINEINDEX und EM_LINEFROMCHAR
Delphi-Quellcode:
function GetNoWordWrapSelLinesII(aMemo: Tmemo): String;
var a,e : Integer;
    s : String;

  function GetLineEnd: Integer;
  begin
    Result := aMemo.Perform(EM_LINEINDEX, e, 0) + Length(aMemo.Lines[e]) +1;
  end;

begin
  with aMemo do
    begin
    s := Text;
    a := SendMessage(Handle, EM_LINEFROMCHAR, SelStart, 0);
    e := a;
    while (a > 0) and (s[Perform(EM_LINEINDEX, a, 0)-1] <> #13) do
     dec(a);
    while (e < Lines.Count -1) and
          (s[GetLineEnd] <> #13) do
      inc(e);
    a := Perform(EM_LINEINDEX, a, 0) +1;
    e := GetLineEnd;
    Result := Copy(s,a,e-a);
    end;
end;
WordWrap temporär aufheben
Delphi-Quellcode:
function GetNoWordWrapSelLinesI(aMemo: Tmemo): String;
var SelStartTmp, SelLengthTmp, LineIndex : Integer;
    OldWordWrap : Boolean;
begin
  Result := '';
  with aMemo do
    begin
    SelStartTmp := SelStart;
    SelLengthTmp := SelLength;
    Lines.BeginUpdate;
    OldWordWrap := WordWrap;
    WordWrap := False;
    SelStart := SelStartTmp;
    LineIndex := SendMessage(Handle, EM_LINEFROMCHAR, SelStart, 0);
    Result := Lines[LineIndex];
    WordWrap := OldWordWrap;
    SelStart := SelStartTmp;
    SelLength := SelLengthTmp;
    Lines.EndUpdate;
    end;
end;
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
  Mit Zitat antworten Zitat