Y
yuan2705
Unregistered / Unconfirmed
GUEST, unregistred user!
在DELPHI6中我做一个简单的打字练习,遇到了一个问题想请教各位:在打错字时字体变成
另一种颜色而对的不变,这个代码应该怎样写?以下是我原本的代码
procedure TMainForm.RichEdit2Change(Sender: TObject);
var
I:Integer;
begin
Y:=0;
N:=0;
srzs.Caption:='0';
//输入字数
szdf.Caption:='0';
//得分现在
jczs.Caption:='0';
//正确字数
cwzs.Caption:='0';
//错误字数
srzs.Caption:=IntToStr(Length(RichEdit2.Text));
//输入字数
RichEdit1.SelectAll;
RichEdit1.SelAttributes.Color:=clBlack ;
RichEdit1.SelStart:=0;
RichEdit1.SelLength:= Length(RichEdit2.Text);
RichEdit1.SelAttributes.Color:=clRed ;
RichEdit1.SelStart :=clBlack-1;
RichEdit1.SelLength := 0;
RichEdit1.SelAttributes.Color := clBackground;
for I:= 1 to Length(RichEdit2.Text)do
begin
if copy(RichEdit1.Text,I,1) = copy(RichEdit2.Text,I,1) then
Y:=Y+1 else
N:=N+1 ;
jczs.Caption:=IntTostr(Y);
//正确字数
cwzs.Caption:=IntTostr(N);
//错误字数
szdf.Caption:=IntTostr(Length(RichEdit2.Text)-5*N);
//现在得分
end;
end;
另一种颜色而对的不变,这个代码应该怎样写?以下是我原本的代码
procedure TMainForm.RichEdit2Change(Sender: TObject);
var
I:Integer;
begin
Y:=0;
N:=0;
srzs.Caption:='0';
//输入字数
szdf.Caption:='0';
//得分现在
jczs.Caption:='0';
//正确字数
cwzs.Caption:='0';
//错误字数
srzs.Caption:=IntToStr(Length(RichEdit2.Text));
//输入字数
RichEdit1.SelectAll;
RichEdit1.SelAttributes.Color:=clBlack ;
RichEdit1.SelStart:=0;
RichEdit1.SelLength:= Length(RichEdit2.Text);
RichEdit1.SelAttributes.Color:=clRed ;
RichEdit1.SelStart :=clBlack-1;
RichEdit1.SelLength := 0;
RichEdit1.SelAttributes.Color := clBackground;
for I:= 1 to Length(RichEdit2.Text)do
begin
if copy(RichEdit1.Text,I,1) = copy(RichEdit2.Text,I,1) then
Y:=Y+1 else
N:=N+1 ;
jczs.Caption:=IntTostr(Y);
//正确字数
cwzs.Caption:=IntTostr(N);
//错误字数
szdf.Caption:=IntTostr(Length(RichEdit2.Text)-5*N);
//现在得分
end;
end;