AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Suche im Richedit

Ein Thema von theomega · begonnen am 6. Aug 2002 · letzter Beitrag vom 8. Aug 2002
Antwort Antwort
Benutzerbild von d3g
d3g

Registriert seit: 21. Jun 2002
602 Beiträge
 
#1
  Alt 6. Aug 2002, 17:14
Hi theomega,

das dürfte aber nach dem selben Prinzip funktionieren. Ich habe eine Funktionion geschrieben (TSearchTypes entspricht den TSearchTypes des RichEdit).

Code:
procedure BoldText(RichEdit: TRichEdit; Pattern: String; st: TSearchTypes);
type
  TStrArray = array of String;

  function ParseString(s: String; c: Char; Delimiters: Integer): TStrArray;
  var
    i, Count: Integer;
  begin
    // get count of delimiters and format array
    SetLength(Result, Delimiters + 1);
    // put string parts into array
    Count := 0;
    for i := 1 to Length(s) do
      if (s[i] = c) then begin
        Result[Count] := Copy(s, 1, i - 1);
        Delete(s, 1, i);
        Inc(Count);
      end;
    Result[Count] := s;
  end;

var
  StrArray: TStrArray;
  i, StartPos, EndPos, Delimiters: Integer;
begin
  Delimiters := 0;
  for i := 1 to Length(Pattern) do
    if (Pattern[i] = '*') then
      Inc(Delimiters);
  if (Delimiters < 1) then
    Exit;

  SetLength(StrArray, Delimiters + 1);
  StrArray := ParseString(Pattern , '*', Delimiters);
  EndPos := 0;

  while (True) do begin
    // find first part
    StartPos := RichEdit.FindText(StrArray[0], EndPos, Length(RichEdit.Text), st);
    if (StartPos = -1) then
      Exit;
    EndPos := StartPos;

    // found other parts
    for i := 1 to Delimiters do begin
      EndPos := RichEdit.FindText(StrArray[i], EndPos, Length(RichEdit.Text), st);
      if (EndPos = 1) then
        Exit;
    end;

    // set bold
    with RichEdit do begin
      SelStart := StartPos;
      SelLength := EndPos + Length(StrArray[Delimiters]) - StartPos;
      SelAttributes.Style := SelAttributes.Style + [fsBold];
      SelLength := 0;
    end;
  end;
end;
MfG,
d3g
-- Crucifixion?
-- Yes.
-- Good. Out of the door, line on the left, one cross each.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:40 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz