procedure TForm1.BitBtn1Click(Sender: TObject);
var
i:integer;
str:string;
checkBoxs:array[1..3] of Tcheckbox;
begin
checkBoxs[1]:=Checkbox1;
checkBoxs[2]:=Checkbox2;
checkBoxs[3]:=Checkbox3;
//showmessage(checkBoxs[1].Caption);
for i:=1 to 3 do
if checkboxs[i].Checked then
begin
if str='' then
str:=checkboxs[i].Caption
else
str:=','+str+checkboxs[i].Caption+',';
showmessage(str);
end;
end;
我想通过选择checkbox的情况来确定到时在dbgrid中输出的字段.
比如checkbox1.checked咯,那我就显示id字段
像这样.现在我是想用通过这样到时select '''+str+''' from table 这样就好控制咯
不过现在这个str的值得怎么取到咯,两个字段中间不是还有个','
好难控制,哪位大哥教教偶
var
i:integer;
str:string;
checkBoxs:array[1..3] of Tcheckbox;
begin
checkBoxs[1]:=Checkbox1;
checkBoxs[2]:=Checkbox2;
checkBoxs[3]:=Checkbox3;
//showmessage(checkBoxs[1].Caption);
for i:=1 to 3 do
if checkboxs[i].Checked then
begin
if str='' then
str:=checkboxs[i].Caption
else
str:=','+str+checkboxs[i].Caption+',';
showmessage(str);
end;
end;
我想通过选择checkbox的情况来确定到时在dbgrid中输出的字段.
比如checkbox1.checked咯,那我就显示id字段
像这样.现在我是想用通过这样到时select '''+str+''' from table 这样就好控制咯
不过现在这个str的值得怎么取到咯,两个字段中间不是还有个','
好难控制,哪位大哥教教偶
form2.dbgrid1.Columns.Clear;
if(checkbox1.Checked) then
sel:=checkbox1.Caption;
if(checkbox2.Checked) then
sel1:=checkbox2.Caption;
if(checkbox3.Checked) then
sel2:=checkbox3.Caption;
if(form1.checkbox1.Checked) then form2.dbgrid1.Columns.add.FieldName:=sel;
if(form1.checkbox2.Checked) then
form2.dbgrid1.Columns.add.FieldName:=sel1;
if(form1.checkbox3.Checked) then
form2.dbgrid1.Columns.add.FieldName:=sel2; sel:='';
sel1:='';
sel2:='';
form2.show;
//这里写的是三个CHKBOX的代码。多的自己加就可以了。