DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: tigerleentu
今日帖子: 12
在线用户: 19
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 nestle_hcl (gigi) ★☆☆☆☆ -
普通会员
2003/5/15 12:08:43
标题:
你们说我该怎么改 浏览:2337
加入我的收藏
楼主:    adoquery2.Close;
   adoquery2.SQL.Clear;
   adoquery2.SQL.Add('select * from eteaitems');
   adoquery2.Open;
 for i:=0 to adoquery1.RecordCount-1 do
   begin//1
    for j:=0 to adoquery2.RecordCount-1 do
     begin//2
     if tea7[i]=trim(adoquery2.FieldValues['tname']) then
      begin//3
      for a:=0 to 4 do
       for b:=0 to 5 do
       if  (a=strtoint(trim(adoquery2.FieldValues['tweek']))) and  
           (b=strtoint(trim(adoquery2.FieldValues['ttime'])))then
            te[a,b]:=0
         else
         te[a,b]:=1;
     end//3
      else
    for a:=0 to 4 do
     for b:=0 to 5 do
     te[a,b]:=1;
    end;//2
     adoquery2.Next;
 end;//1
我想实现的功能是:从表eteaitems中查找是否有tea7[i]的记录;如果有就执行
    begin//3  
      for a:=0 to 4 do
       for b:=0 to 5 do
       if  (a=strtoint(trim(adoquery2.FieldValues['tweek']))) and  
           (b=strtoint(trim(adoquery2.FieldValues['ttime'])))then
            te[a,b]:=0
         else
         te[a,b]:=1;
     end//3
   如果没有就执行for a:=0 to 4 do
     for b:=0 to 5 do
     te[a,b]:=1;
但是这个程序只能识别eteaitems中最后一条记录,不能实现我要的功能,你们说我该怎么改!
----------------------------------------------
-
作者:
男 hedong (hedong) ★☆☆☆☆ -
盒子活跃会员
2003/5/15 17:42:32
1楼: var
   szSeleSQL, sztweek, szttime: string;
   b: boolean;
begin
   for i:=0 to adoquery1.RecordCount-1 do
   begin
        szSeleSQL := 'select tweek, ttime from eteaitems where tname = '' + tea7[i] + '';
        with adoquery2 do
        begin
              close;
              sql.Clear;
              sql.Add(szSeleSQL);
              open;
              b := eof; 
              if not eof then
              begin
                   sztweek := fieldbyname('tweek').asstring; 
                   szttime := fieldbyname('ttime').asstring;
              end;    
              close; 
        end;  

              if b then     // 找到相同
              begin
                  for a:=0 to 4 do
                    for b:=0 to 5 do
                      if  (a=strtoint(trim(sztweek))) and  
                           (b=strtoint(trim(szttime)))then
                             te[a,b]:=0
                      else
                         te[a,b]:=1;
              end
              else         //  未 找到相同 
                  for a:=0 to 4 do
                    for b:=0 to 5 do
                       te[a,b]:=1;
   end;
end;
----------------------------------------------
-
作者:
男 supermay (supermay) ★☆☆☆☆ -
盒子活跃会员
2003/5/15 19:49:21
2楼: 还用SQL写好一些
----------------------------------------------
链接:https://pan.baidu.com/s/12jzmECYKhGCsHBxz8tmB6w 提取码:pelr --来自百度网盘超级会员V9的分享
作者:
女 ldyocean (ldyocean) ★☆☆☆☆ -
盒子活跃会员
2003/5/15 22:59:53
3楼: var
   szSeleSQL, sztweek, szttime: string;
   b: boolean;
begin
   for a:=0 to 4 do begin
       for b:=0 to 5 do begin
           te[a,b]:=1;
       end;
   end;
   for i:=0 to adoquery1.RecordCount-1 do begin
       szSeleSQL := 'select tweek, ttime from eteaitems where tname = '' + tea7[i] + '';
       with adoquery2 do begin
            close;
            sql.Clear;
            sql.Add(szSeleSQL);
            open;               
//这里得确保顶多只能查到一条记录,不然我想逻辑有问题。
            b:=eof;
            if not eof then begin
               sztweek := fieldbyname('tweek').asstring; 
               szttime := fieldbyname('ttime').asstring;
            end;    
            close; 
       end; 
       if not b then
          te[strtoint(trim(sztweek)),strtoint(trim(szttime))] :=0
//此处也不太懂,每循环一次,数组就可能有不同的地方被重写了,要干吗啊?
   end;

    呵呵,以上代码大部分照抄1楼的,我只是让他再少几次循环而已。
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行74.21875毫秒 RSS