我的问题如同题目所说的那样!
比如我想控制一个控件的可用状态
BitBtn1.Enabled:= True;
能没有什么函数可以达到这样的目的呢:
Str1 := 'BitBtn1.Enabled := True';
Fun(Str1)
我只是想知道能不能实现,如果可以怎么实现呢?谢谢了!
比如我想控制一个控件的可用状态
BitBtn1.Enabled:= True;
能没有什么函数可以达到这样的目的呢:
Str1 := 'BitBtn1.Enabled := True';
Fun(Str1)
我只是想知道能不能实现,如果可以怎么实现呢?谢谢了!
我给你举个例子,你修改就可以用了
procedure TextClear(AForm:Tform);
Var
Index:integer; //序号
IndexComponent:integer; //控件序号
//TDBEdit: 0
//TwwDBLookupCombo: 1
//TEdit: 2
//TwwDBDateTimePicker: 3
//TDBComboBox: 4
//TDBMemo 5
ComponentNameLength:integer; //控件名称长度
ComponentName:string; //控件名称
LastTwoString:string; //后两位为cx
begin
for Index:=0 to AForm.ComponentCount-1 do
begin
if (Aform.Components[Index] is TComboBox) then
if (Aform.Components[Index] as TComboBox).Enabled then
(Aform.Components[index] as TComboBox).Text:='';
if (Aform.Components[Index] Is TDBEdit) then
if (Aform.Components[Index] as TDBEdit).DataField='' then
(Aform.Components[Index] as TDBEdit).Text:='';
if (Aform.Components[Index] Is TEdit) then
if (Aform.Components[Index] as TEdit).Enabled then
(Aform.Components[Index] as TEdit).Text:='';
if (Aform.Components[Index] Is TwwDBLookupCombo) then
if (Aform.Components[Index] as TwwDBLookupCombo).DataField='' then
(Aform.Components[Index] as TwwDBLookupCombo).Text:='';
if (Aform.Components[Index] Is TwwDBDateTimePicker) then
if (Aform.Components[Index] as TwwDBDateTimePicker).DataField='' then
(Aform.Components[Index] as TwwDBDateTimePicker).Text:='';
if (Aform.Components[Index] Is TwwDBComboBox) then
if (Aform.Components[Index] as TwwDBComboBox).DataField='' then
(Aform.Components[Index] as TwwDBComboBox).Text:='';
if (Aform.Components[Index] Is TwwDBLookUpComboDlg) then
if (Aform.Components[Index] as TwwDBLookUpComboDlg).DataField='' then
(Aform.Components[Index] as TwwDBLookUpComboDlg).Text:='';
if (Aform.Components[Index] Is TComboBox) then
begin
(Aform.Components[Index] as TComboBox).ItemIndex:=-1;
end;
end;
end;
还有其它同志们有其它的方法吗?
function a1(str1:string);
var
index:integer;
begin
for Index:=0 to Form1.ComponentCount-1 do
begin
if (form1.Components[Index] Is TButton) then
if (form1.Components[Index] as TButton).Name=str1 then
(form1.Components[Index] as TButton).Enabled:=True;
end;
end;
//你的程序的写法: While not adoQuery1.eof then
begin
Str1 := adoQuery1.fields.FieldByName('MoKuai').asstring +
'.Enabled := True';
a1(Str1);
adoquery1.next;
end;
Str1 := 'BitBtn1.Enabled := True';
Fun(Str1)
你要分析你的字符串。但是做个通用的函数还是可以,但是你传的字符串要有规律。
第一个字符串是对象,第二个是方法,最后才是值了,这个值就一定要事前知道是什么类型的值,比如是BOOLEAN,INTEGER,...的。
'BitBtn1.Enabled := @boolean@True@';第1,2个@表示接下来的是boolean变量,2,3之间表示用字符表示的值