一个由ABCDEF组成的字符串,可能的结果如:
ABC
ABCD
AB
ABCDEF
ABCD
ACD
ABEF
...这个由六个字符组成的字符串中每个字符对应一个edit控件,如:
A 对应控件 EDIT1
B 对应控件 EDIT2
C 对应控件 EDIT3
D 对应控件 EDIT4
E 对应控件 EDIT5
F 对应控件 EDIT6问题:
在一个文本框(strEdit)中输入上述字符串中的任何一组时,点击按钮能够将对应的EDIT控件的背景颜色同时改变?
求教老师
ABC
ABCD
AB
ABCDEF
ABCD
ACD
ABEF
...这个由六个字符组成的字符串中每个字符对应一个edit控件,如:
A 对应控件 EDIT1
B 对应控件 EDIT2
C 对应控件 EDIT3
D 对应控件 EDIT4
E 对应控件 EDIT5
F 对应控件 EDIT6问题:
在一个文本框(strEdit)中输入上述字符串中的任何一组时,点击按钮能够将对应的EDIT控件的背景颜色同时改变?
求教老师
解决方案 »
- 自己写的一个DLL 静态调用没有问题,动态调用老是出错,请高手帮忙!
- 第 1 行: ',' 附近有语法错误
- 请教cxgrid的过滤器生成器的中文显示问题
- Delphi 7 简单问题希望高手帮助
- 求救,如何过滤中文和英文?
- RichEdit1.SelAttributes.Protected := true; 怎么发消息给RICHEDIT1,将Protected设为False???? 就是取消某字符串的保护属性,可以继续编辑此字符串!
- 字符串分割问题,急!!在线等
- 窗体显示的问题,大家来强分
- 如何在Delphi中调用SQL Server中的存储过程?
- postmessage的使用
- 初学者提问:下面的代码哪里错了?
- 求一算法,关于SQL表 和 TreeView!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
A: TEdit;
B: TEdit;
C: TEdit;
edt: TEdit;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);
var
Comp:TComponent;
begin
Comp:=FindComponent(edt.Text);
if (Comp <> nil) and (Comp is TEdit) then
TEdit(Comp).Color:=clSkyBlue ;
end;end.
经测试,您的代码一次只能输入一个字符选中一个Edit控件,我想是输入一组字符,如ABC能够同时改变三个Edit控件的背景色,如何做呢?
procedure TForm1.btn1Click(Sender: TObject);
var
Comp:TComponent;
I:Integer;
begin
for I:=1 to Length(edt.Text) do
begin
Comp:=FindComponent(Copy(edt.Text,I,1));
if (Comp <> nil) and (Comp is TEdit) then
TEdit(Comp).Color:=clSkyBlue ;
end;
end;
var
str: string;
begin
str:= trim(strEdit.text);
for i:= 0 to length(str) - 1 do
(FindComponent(edit+inttostr(ord(str[i+1])-64)) as tedit).color:= clred;
end;
未测,一般能行
procedure TForm1.Button1Click(Sender: TObject);
var
str: string;
i: integer;
begin
str:= 'AC';
for i:= 0 to length(str) - 1 do
(FindComponent('edit'+inttostr(ord(str[i+1])-64)) as tedit).color:= clred;
end;
刚测,可以了