if语句的简单问题 ( 积分: 20 )

  • 主题发起人 主题发起人 翁富大
  • 开始时间 开始时间

翁富大

Unregistered / Unconfirmed
GUEST, unregistred user!
if dbgrid.selectedfield.fieldname = 'sds' or dbgrid.selectedfield.fieldname = 'sds2' or dbgrid.selectedfield.fieldname = '3sdsd' or dbgrid.selectedfield.fieldname = 'sds4' then do
有没有简便的写法,不让dbgrid.selectedfield.fieldname多次出现。多谢了
 
if dbgrid.selectedfield.fieldname = 'sds' or dbgrid.selectedfield.fieldname = 'sds2' or dbgrid.selectedfield.fieldname = '3sdsd' or dbgrid.selectedfield.fieldname = 'sds4' then do
有没有简便的写法,不让dbgrid.selectedfield.fieldname多次出现。多谢了
 
sl: stringlist;

sl.text := 'sds'#13#10'sds2'#13#10'3sdsd#13#10'sds4
if sl.indexof(dbgrid.selectedfields.fieldname) >= 0 then
 
丫,是个新思路啊,我试试先
 
with dbgrid.selectedfield do
if fieldname = 'sds' or fieldname = 'sds2' or fieldname = '3sdsd' or fieldname = 'sds4' then
 
with dbgrid.selectedfield do
begin
if fieldname = 'sds' or
fieldname = 'sds2' or
..... then
begin
{你的代码}
end;
end;

或者:
var
dbgField: TField;
begin
if dbgField.fieldname = 'sds' or
dbgField.fieldname = 'sds2' or
dbgField.fieldname = '3sdsd' or
dbgField.fieldname = 'sds4' then
begin
.......
end;
end;
 
var
str: String;

str := dbgrid.selectedfield.fieldname;
if str = 'sds' or str = 'sds2' or str = '3sdsd' or str = 'sds4' then do
 
也是个新思路呀
不错的
 
with dbgrid.selectedfield do
if (fieldname = 'sds') or
(fieldname = 'sds2') or
(fieldname = '3sdsd') or
(fieldname = 'sds4') then
begin
......
end;
 
If Pos(dbgrid.selectedfields.fieldname, 'sds,sds2,3sdsd,sds4')>0 Then
...
 
可是这种方法要创建实例吧,还有简便的么[:D]
 
if pos(format(',%s,',[dbgrid.selectedfield.fieldname]),
format(',%s,%s,%s,$s,',[sds'','sds2','sdsda','sd4']))>0 then

这样才会只出现一次dbgrid.selectedfield.fieldname,而且不用新建对象.
 
xianguo的答案正是我想要的,不过你的好像不是十分完善吧,我改了一下:
If Pos(','+dbgrid.selectedfields.fieldname+',', ',sds,sds2,3sdsd,sds4,')>0 Then


上面的daqun,不好意思,你的答案很好,可惜我分配完分数才看见,sorry
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部