Solved

Changing color of font automatically

Posted on 1997-07-20
1
228 Views
Last Modified: 2013-12-03
Is it possible when loading a *.rtf document in richedit, which contains any black font to automatically convert to white font at loading.
0
Comment
Question by:hellfire052497
1 Comment
 
LVL 4

Accepted Solution

by:
erajoj earned 40 total points
ID: 1339317
This works but it isn't the most beautiful piece of code
I have come up with. It is not very fast but it does the job.
This is quite a complicated problem and it's really worth
more than 40pts, but this solution is ;^):

procedure TfrmMain.LoadRTFBlackToWhite(FileName: string);
const
  BlackAttr = $80000008; // don't ask me why, ought to be $0
var
  Index1, Index2 : Integer;
  First, Last    : Cardinal;
begin
  RichEdit1.Hide;
  RichEdit1.Lines.LoadFromFile(FileName);
  SendMessage(RichEdit1.Handle, EM_SETSEL, 0, -1); // Set cursor at last position
  SendMessage(RichEdit1.Handle, EM_GETSEL, Integer(@First), Integer(@Last)); // Get gursor position
  Index1  := 0; // First char
  repeat  // Yes it's true, scan through every char. Might be slow on large files!
    SendMessage(RichEdit1.Handle, EM_SETSEL, Index1, Index1+1); // Select char
    with RichEdit1.SelAttributes do
    if (Color=BlackAttr) or (Color=clBlack) then begin
      Index2 := Index1;
      repeat // Find end of color paragraph
        SendMessage(RichEdit1.Handle, EM_SETSEL, Index2, Index2+1);
        Inc(Index2);
      until ((Color<>BlackAttr) and (Color<>clBlack)) or (Index2>=Last);
      SendMessage(RichEdit1.Handle, EM_SETSEL, Index1, Index2-1);
      RichEdit1.SelAttributes.Color := clWhite; // replacement
      Index1 := Index2-1;
    end;
    Inc(Index1);
  until (Index1>=Last);
  SendMessage(RichEdit1.Handle, EM_SETSEL, -1, 0); // Select nothing and put cursor last
  RichEdit1.Show;
end;

/// John
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adobe Acrobat Pro: how to copy style? 2 114
How to build JSON File in Delphi 6 3 45
PHP preg_replace code convert to Delphi 14 66
RESTRequest Parameter 4 42
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question