调试成功
建一个Form,放一个RichEdit1,一个Edit1,把下边的代码复制上去就可以了
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StrUtils, StdCtrls, ComCtrls, IdTrivialFTPBase;
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure RichEdit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
function CurrText: TTextAttributes;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.CurrText: TTextAttributes;
begin
if (RichEdit1.SelLength=0) and (Trim(RichEdit1.Text)='') then
begin
Result :=RichEdit1.DefAttributes;
RichEdit1.DefAttributes :=Result;
end
else
begin
Result :=RichEdit1.SelAttributes;
end
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RichEdit1.Text :='';
end;
procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
var
S1,S2: String;
begin
S1 :=MidStr(Edit1.Text,RichEdit1.SelStart+1,1);
S2 :=Key;
if S1<>S2 then
begin
CurrText.Color :=clRed;
end
else
CurrText.Color :=clBlack;
end;
end.
给分啊!