Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi RichEdit und Enter im Text ?!? (https://www.delphipraxis.net/48491-richedit-und-enter-im-text.html)

spacewolf 26. Jun 2005 10:33


RichEdit und Enter im Text ?!?
 
Moin,

sacht weiß jemand wie man im RichEdit feststellt ob hinter einem Wort ein Enter ist oder nicht ?
Ein Wort zu selektieren das schaff ich jetzt schon ;-)
Aber festzustellen ob nach dem Wort sich eine oder zwei Leerzeilen befinden, da weiß ich nicht wie es geht.
Und dann würd ich noch gern das Enterzeichen (\par) einfügen lassen...

Tja, falls jemand ne Lösung hat... wär toll

THANX and be blessed

say Andreas

Delphi-Quellcode:
var
  foundat : integer;
begin
  with RichEdit do
  begin
    foundat := FindText('Titel:',0,length(Text),[stMatchCase]);
    if foundat > 0 then
    begin
      SetFocus;
      SelStart := FoundAt;
      SelLength := Length('Titel:');
    end;
  end;
end;

marabu 26. Jun 2005 13:14

Re: RichEdit und Enter im Text ?!?
 
Hallo Andreas,

nimm dir was du brauchst:
Delphi-Quellcode:
uses
  StrUtils;

function TDemoForm.HasTail(line, tail: string): boolean;
begin
  Result := RightStr(line, Length(tail)) = tail;
end;

procedure TDemoForm.FindButtonClick(Sender: TObject);
var
  iLine, iStart, iEmpty: integer;
begin
  with RichEdit do begin
    // character offset der Fundstelle
    iStart := FindText(FindEdit.Text, 0, GetTextLen, []);
    // cursor dahinter positionieren
    SelStart := iStart + Length(FindEdit.Text);
    // Zeilenumbruch hat Länge 2
    SelLength := 2;
    if SelText = #13#10 then begin
      // steht am ende, jetzt leerzeilen zählen
      iEmpty := 0;
      repeat
        Inc(iEmpty);
        SelLength := SelLength + 2;
      until not HasTail(SelText, #13#10);
      ShowMessage(Format(
        '"%s" steht am Zeilenende, gefolgt von %d Leerzeilen',
        [FindEdit.Text, Pred(iEmpty)]
      ));
    end else begin
      // steht nicht am ende, also zeilenumbruch einfügen
      SelLength := 0;
      SelText := #13#10;
    end;
  end;
end;
Grüße vom marabu

spacewolf 26. Jun 2005 14:49

danke !!!
 
danke das funzt... super :-)

was macht eigendlich HasTail ???

marabu 26. Jun 2005 14:59

Re: RichEdit und Enter im Text ?!?
 
HasTail() erhöht in meinen Augen die Lesbarkeit des Codes - mehr nicht.

marabu


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:07 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz