Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Delphi Richedit Parsen und Fontcolor auslesen (https://www.delphipraxis.net/174151-delphi-richedit-parsen-und-fontcolor-auslesen.html)

ReVenGer 7. Apr 2013 11:34

Delphi Richedit Parsen und Fontcolor auslesen
 
Hi,
ich möchte in einem Richedit den Text inkl. Fontcolor auslesen, und Fontcolor durch vorgegebene Strings ersetzen und in ein anderes Richedit Feld einlesen.

als Beispiel: (clyellow)Hallo(clred)welt! -> _gelb_Hallo_rot_welt

Nur leider finde ich keine Info wie ich die Fontfarbe parsen und ersetzen kann.

Gruß

Furtbichler 7. Apr 2013 11:44

AW: Delphi Richedit Parsen und Fontcolor auslesen
 
Erzeug Dir doch einfach mal bunten Text im Wordpad und schau dir den RTF-Code an. Ich bezweifle allerdings, das Du dort Farbennamen sehen wirst, höchstens RGB-Werte.

ReVenGer 7. Apr 2013 11:45

AW: Delphi Richedit Parsen und Fontcolor auslesen
 
Die RGB Werte reichen ja schon als Identifikation. Die könnte ich dann entsprechend ersetzen und den Text inkl. verarbeitetem RGB Code in ein anderes Richedit einfügen.
Nur wie Parse ich das?

void __fastcall TForm7::Button1Click(TObject *Sender)
{
int textLength, i;
TConsistentAttributes textAttribute;
TColor textColor;

textLength = RichEdit1->Text.Length() ;

for (i = 0; i < textLength; i++) {
RichEdit1->SelStart = i;
RichEdit1->SelLength = 1;
textAttribute = RichEdit1->SelAttributes->ConsistentAttributes;
if (textAttribute.Contains(caColor))
{
textColor = RichEdit1->SelAttributes->Color;
if (textColor == clRed) {

}

}

}

So würde ich es in C++ machen.

Volker Z. 7. Apr 2013 13:14

AW: Delphi Richedit Parsen und Fontcolor auslesen
 
Hallo,

warum ConsistentAttributes? Aus der OH:
Zitat:

property ConsistentAttributes: TConsistentAttributes read GetConsistentAttributes;
Zeigt an, welche der Eigenschaften des TTextAttributes-Objekts innerhalb der aktuellen Auswahl im RTF-Steuerlement konsistent sind.
Bei nur einem selektiert Zeichen kann nicht viel konsistent/inkonsitent sein.

Mit Deinem Ansatz:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  s : string;
  i : Integer;
  c : TColor;
begin
  RichEdit1.SelStart := i;

  c := RichEdit1.SelAttributes.Color;
  if c < $7FFFFFFF then
    Inc (c)
  else
    Dec (c);

  s := '';
  for i := 1 to Length (RichEdit1.Text) do
    begin
      RichEdit1.SelStart := i;
      if c <> RichEdit1.SelAttributes.Color then
        begin
          c := RichEdit1.SelAttributes.Color;
          s := s + '_' + ColorToString (c) + '_'
        end;
      s := s + RichEdit1.Text [i]
    end
end;
Sollte dann Hallowelt! -> _gelb_Hallo_rot_welt! als Ergebnis kommen.

Gruß

ReVenGer 7. Apr 2013 20:06

AW: Delphi Richedit Parsen und Fontcolor auslesen
 
Vielen Dank Volker,
deshalb hat das mit ConsistentAttributes auch nicht funktioniert..

Gruß


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