var
  gl,sw:integer;
begin
  gl := 0;
  sw := 0;
  table1.First;
  while not table1.eof do
    begin
      if Copy(Trim(table1.FiledByName(‘用户编号’).AsString),1,2) = 'gl' then   
        Inc(gl);
      if Copy(Trim(table1.FiledByName(‘用户编号’).AsString),1,2) = 'sw' then   
        Inc(sw);
      Table1.Next;
    end;
    Edit1.Text := IntToStr(gl);
    Edit2.Text := IntToStr(sw);
end;

解决方案 »

  1.   

    我觉得你这样不行的,这样的话是精确匹配,可能会一个也找不到。我想最好用SQL,用like加上一个通配符。
      

  2.   

    用query  method 1: 
      var 
         usercount : integer  ;
        
         query1.sql.add (  select bh from tblnamn where id like 'gl%' )
         query1.active := true ;
          
         usercount := query1.recordcount ;method 2 : 
          用 table 的 filter 属性 
          table1.recordcount   得到 
    但原理是一样的 !! 
      
            
        
          
      

  3.   

    query1.sql=select count(*) from table1 where 用户编号 like gl%
    query2.sql=select count(*) from table1 where 用户编号 like sw%query1.open
    query2.open
    edit1.text:=inttostr(query1.fields[0].asinteger);
    edit2.text:=inttostr(query2.fields[0].asinteger);
      

  4.   

    用你的方法也可以  :Var
    U:integer;
    Begin
      While not table1.eof do
        Begin
          If pos ( 'gl', table1.filedbyname(‘用户编号’) >0 then u:=u+1;/这句我也不知怎样表达
          Table1.next;
        End;
        Edit1.text:=inttostr(u);
      

  5.   

    有那么麻烦吗,
    一句:
    select count(*) from 表名 where 字段名 like 'gl%'
      

  6.   

    用sql解决简单:
    select 
    (select count(*)  from table1 where instr(用户编号,'gl')>0 ) as gl开头的用户,
    (select count(*)  from table1 where instr(用户编号,'sw')>0 ) as sw开头的用户
    from dual
    这是ORACLE中的用法,其它数据库也大同小异,函数名不一样而已。如果用代码写的话, qybao(阿宝) 的方法就可以,
      

  7.   

    我也会选用POS的方法,但可能会出错,et SQL语句进行的模糊查询也会出相同的错误,这就要保证你的字段中gl和sw之间都是独立的,如果某条记录里有gl0sw0001就会出现统计错误,把这段记录统计两次了。所以你要用模糊查询的方法,就要强性规定gl和sw为关键字,不能在字段值里出现。
      

  8.   

    jixinfa(DELHPI程序员):
    我试了你的为什么有如下错误
    Token not found
    Token:gl
      

  9.   

    加上引号就可以了
    query1.sql=select count(*) from table1 where 用户编号 like 'gl%'
    query2.sql=select count(*) from table1 where 用户编号 like 'sw%'query1.open
    query2.open
    edit1.text:=inttostr(query1.fields[0].asinteger);
    edit2.text:=inttostr(query2.fields[0].asinteger);