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 Mehrer FontStyles zuweisen (https://www.delphipraxis.net/27303-mehrer-fontstyles-zuweisen.html)

Luckie 7. Aug 2004 17:21


Mehrer FontStyles zuweisen
 
Ich habe mir eine Funktion geschrieben, die alle Wörter aus einer Liste in einem RichEdit markiert:
Delphi-Quellcode:
function MarkWords(RichEdit: TRichEdit; Words: TStrings; FontStyle: TFontStyle;
  Color: TColor): Cardinal;
var
  i: Integer;
  LastWordPos: Integer;
begin
  LastWordPos := 0;
  for i := 0 to Words.Count - 1 do
  begin
    while LastWordPos < 500 do
    begin
      LastWordPos := FindWord(LastWordPos, RichEdit.Text, Words[i]);
      RichEdit.SelStart := LastWordPos;
      RichEdit.SelLength := length(Words[i]);
      RichEdit.SelAttributes.Color := Color;
      RichEdit.SelAttributes.Style := [FontStyle];
      LastWordPos := LastWordPos + 1;
    end;
    LastWordPos := 0;
  end;
  RichEdit.SelStart := 0;
  result := 0;
end;
Aufruf mit
Delphi-Quellcode:
MarkWords(RichEdit1, sl, fsBold, clRed);
Wie bekomme ich es jetzt hin, dass ich gleich mehrer Styles (fsBold, fsItalic) zuweisen kann? Und wie hebe ich es wieder auf?

mirage228 7. Aug 2004 17:24

Re: Mehrer FontStyles zuweisen
 
Hi,

der Zuweis ist nicht schwer:
Delphi-Quellcode:
function MarkWords(RichEdit: TRichEdit; Words: TStrings; FontStyles: TFontStyles;
  Color: TColor): Cardinal;
var
  i: Integer;
  LastWordPos: Integer;
begin
  LastWordPos := 0;
  for i := 0 to Words.Count - 1 do
  begin
    while LastWordPos < 500 do
    begin
      LastWordPos := FindWord(LastWordPos, RichEdit.Text, Words[i]);
      RichEdit.SelStart := LastWordPos;
      RichEdit.SelLength := length(Words[i]);
      RichEdit.SelAttributes.Color := Color;
      RichEdit.SelAttributes.Style := FontStyles;
      LastWordPos := LastWordPos + 1;
    end;
    LastWordPos := 0;
  end;
  RichEdit.SelStart := 0;
  result := 0;
end;

// Aufruf:
MarkWords(RichEdit1, sl, [fsBold, fsItalic], clRed);
mfG
mirage228

Luckie 7. Aug 2004 17:27

Re: Mehrer FontStyles zuweisen
 
Ah ja. Danke. Dieses blöde "s". :roll:


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:45 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