100分----RichEdit控件中对输入的汉字作判断,正确的字显示蓝色,错误的显红色 在做打字程序时,在RichEdit控件中对输入的汉字作判断,正确的字显示蓝色,错误的显红色,怎么写程序? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 procedure TForm1.RichEdit1Change(Sender: TObject);var Startpos,Toend,x,y:integer; curstring:string;begin curstring:=RichEdit1.Lines[RichEdit1.Lines.Count-1];; StartPos := 0; ToEnd := length(Richedit2.text)-1; X := Richedit2.FindText(curstring,StartPos,toEnd,[stMatchCase]); if x<>-1 then begin Richedit2.SetFocus; Richedit2.selstart := X; RichEdit2.SelLength := Length(curstring); RichEdit2.SelAttributes.Color:=clRed; end;end; //判断汉字的方法procedure TForm1.Button1Click(Sender: TObject);var s:string;begin s:=Edit1.Text; if ord(s[9])>128 then ShowMessage('该位置字符是汉字');end; 我代码是这样写的,不能正确显示颜色,帮我看看有什么问题?procedure TFrmTextInput.RichEditInputChange(Sender: TObject);var i,j:integer;//i,j 分别记录样本字符串和录入字符串的字符的位置 Cusor:integer;//记录光标的位置 index:integer; Samplelength,InputLength:integer;//记录两字符串的总长度begin strSample:=RichEditSample.Text; strInput:=RichEditInput.Text; Cusor:=RichEditInput.SelStart; index:=cusor div 2; //使光标位置和字符串数组的位置一致 // SampleLength:=length(strSample); // InputLength:=length(strInput); // 将输入的字体颜色预置为蓝颜色 RichEditInput.DefAttributes.Color:=clBlue; //对输入的字是否正确作判断,若不正确,则改变它的颜色 if cusor>=1 then if strInput[index]<>strSample[index] then begin // 将刚才输入的字置于红颜色 RichEditInput.selStart:=cusor-2 ; RichEditInput.selLength:=2; RichEditInput.SelAttributes.Color:=clRed; // 恢复光标的位置 RichEditInput.selStart:=cusor; // 重置于蓝颜色 RichEditInput.selAttributes.color:=clBlue; end; RichEdit 设置下标 SQL语句请教? 如何来释放窗体的关闭事件 请位大侠,谁做过制作启动盘的程序?小弟请教了 由于分辨率不同解决字体的问题 如何在主程序中传递TMemoryStream或TStringList类型参数给DLL? 过年了,都进来拿年终奖金! 主程序打开一个word文档,word文档显示后,主程序失去焦点,交给打开的word文档? 初级问题:添加新的method和procedure只能先手工输入声明,再输入实现吗?有没有象VC里那样简单的方法? 在戴妃中用过TTS的人请进 导出到excel 如何实现
var Startpos,Toend,x,y:integer;
curstring:string;
begin
curstring:=RichEdit1.Lines[RichEdit1.Lines.Count-1];;
StartPos := 0;
ToEnd := length(Richedit2.text)-1;
X := Richedit2.FindText(curstring,StartPos,toEnd,[stMatchCase]);
if x<>-1 then
begin
Richedit2.SetFocus;
Richedit2.selstart := X;
RichEdit2.SelLength := Length(curstring);
RichEdit2.SelAttributes.Color:=clRed;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
s:=Edit1.Text;
if ord(s[9])>128 then
ShowMessage('该位置字符是汉字');
end;
var
i,j:integer;//i,j 分别记录样本字符串和录入字符串的字符的位置
Cusor:integer;//记录光标的位置
index:integer;
Samplelength,InputLength:integer;//记录两字符串的总长度begin
strSample:=RichEditSample.Text;
strInput:=RichEditInput.Text;
Cusor:=RichEditInput.SelStart;
index:=cusor div 2; //使光标位置和字符串数组的位置一致
// SampleLength:=length(strSample);
// InputLength:=length(strInput);
// 将输入的字体颜色预置为蓝颜色
RichEditInput.DefAttributes.Color:=clBlue;
//对输入的字是否正确作判断,若不正确,则改变它的颜色
if cusor>=1 then
if strInput[index]<>strSample[index] then
begin
// 将刚才输入的字置于红颜色 RichEditInput.selStart:=cusor-2 ;
RichEditInput.selLength:=2;
RichEditInput.SelAttributes.Color:=clRed;
// 恢复光标的位置
RichEditInput.selStart:=cusor;
// 重置于蓝颜色
RichEditInput.selAttributes.color:=clBlue;
end;