远程访问数据库
为了保证速度
一张数据表要经常访问
有没有办法把它封成一个内存中的数据结构?

解决方案 »

  1.   

    当然可以了
    可以把query的cache打开
    还有外部空间,比如rxlib的rxmemdate之类很好用的
      

  2.   

    一个最简单的办法:用clientDateset的data 属性
      

  3.   

    提供一个办法,别见笑:把你这张表的字段结构定义成一个Record,一次性读取这张表的数据放入Record中,以后要查找数据,就直接操作这个Record。
      

  4.   

    对于查询统计的数据(数据在不断的变动)
    查询起来很费时
       用动态数组+record 
      

  5.   

    不好意思,现在才看到你发的消息。我的想法是,比如你的表结构是Addr(char 15),Name(char 10),Phone(char 11),那么你可以定义一个和表结构一致record,例如TMyTable,如果说你要读取的表的内容是固定的,那么可以定义一个动态的数组MyTable:array of TMyTable。它的长度就是表的数据量,即多少条记录,SetLength(MyTable,RecordCount)。查询的时候,可以使用for循环,根据相关的内容来对需要的数据进行匹配。
      

  6.   

    不明白为什么不用CLIENTDATASET他本来就是一个内存中的表,而且提供了宛备的对于此表的操作;相信可以满足你的任何关于表的需要;
      

  7.   

    设计一个类,属性和表字段属性对应,加些属性存取方法(可选),使用中一条记录产生一个对象,用Tlist管理这些对象。---灵活
      

  8.   

    to ShanShiMin(Delphi+C#=我的最爱) 
      你可以进入系统时 把它存入动态数组中 
    对于一些功能你可以写成函数 如下:
    定义发下
     type inv_unit=Record
              cinvcode : String;
              inv_plan : real;       // -1 表示没有设置
              inv_sum : real;
        end;
        TSel_inv = Array of inv_unit;//数组初始化 
    procedure tloginfrm.init_inv(chandler:string;dvouchdate:String);
    var  strsql,cinvcode:string;
         inum:real;
         i:integer;
         tmp:inv_unit;
    begin
        //  把计划信息存入动态数组中
           strsql:='select cinvcode,iQuantity as inum  from plan where  cpercode='''+chandler+'''';
            with dm do
            begin
                 if ADOQ_cinit_inv_num.active then ADOQ_cinit_inv_num.active:=false;
                 ADOQ_cinit_inv_num.sql.Clear;
                 ADOQ_cinit_inv_num.sql.add(strsql);
                 ADOQ_cinit_inv_num.open;
                 while not  ADOQ_cinit_inv_num.eof  do
                  begin
                     cinvcode:=trim(ADOQ_cinit_inv_num.FieldByName('cinvcode').Asstring);
                     inum:=ADOQ_cinit_inv_num.FieldByName('inum').asfloat;
                       add_sel_inv(cinvcode,inum,0);  //增加过程
                       ADOQ_cinit_inv_num.next;
                  end;
                  ADOQ_cinit_inv_num.Close;
        //把预订信息存入数组中
           strsql:='select cinvcode,sum(iQuantity) as inum   from Tmp_Rdrecord  as rds join Tmp_Rdrecords as rd  on rd.irdid=rds.irdid    ';
           strsql:=strsql+' where  date(dvouchdate)='''+yw_date+'''  and ';
           strsql:=strsql+' chandler='''+chandler+''' and (cInvalider IS NULL) group by cinvcode ';
           if    adoq_cinv.active  then  adoq_cinv.Close;
           Adoq_cinv.sql.Clear;
           Adoq_cinv.sql.add(strsql);
           Adoq_cinv.Active:=TRUE;
           while not adoq_cinv.eof  do
           begin
             cinvcode:=trim(ADOQ_cinv.FieldByName('cinvcode').Asstring);
             inum:=ADOQ_cinv.FieldByName('inum').asfloat;
             i:=f_sel_id(cinvcode);
             if i=-1 then
              begin  //add  inv_unit
                {tmp.cinvcode:=cinvcode;
                tmp.inv_plan:=-1;
                tmp.inv_sum:=inum;
                setlength(SEL_INV,Length(SEL_INV)+1);
                SEL_INV[Length(SEL_INV)-1]:=tmp;   }
                add_sel_inv(cinvcode,-1,inum);
              end
            else
              SEL_INV[I].inv_sum:=inum;  // end  of if i=-1
              adoq_cinv.next;
            end;   //end of   while
            adoq_cinv.Close;
         end; // end of with  dm do
    //查找函数
      function  Tloginfrm.F_sel_id(cinvcode:string):integer ;
    var
            i:integer;
    begin
            for  i:=0 to  length(SEL_INV)-1  DO
            begin
                    if  cinvcode=sel_inv[i].cinvcode  then
                            begin
                              f_sel_id:=i;
                              exit;
                            end;
            end;
            f_sel_id:=-1;  //没有找到
    end ;///增加
    procedure Tloginfrm.add_sel_inv(cincode:string;inv_plan:real;inv_sum:real);
    var
        i:integer;
            tmp:inv_unit;
    begin
         tmp.cinvcode:=cincode;
         tmp.inv_plan:=inv_plan;
         tmp.inv_sum:=inv_sum;
         setlength(SEL_INV,Length(SEL_INV)+1);
         SEL_INV[Length(SEL_INV)-1]:=tmp;
    END;