写了个程序,需要使用多个线程,从数据库里读取配置和写日志到数据库。有哪位高手给说下怎么写,最好有例子参考。

解决方案 »

  1.   


      如果是从数据库读配置,query组件连dataprovider读即可,取出数据集后locate每个参数配置即可
    写日志可直接封装个函数,因为可能多次用,省得麻烦
      

  2.   

    没有FORM 那adoconntection 和 adoquery 控件往哪里放,
    再个,参照有form的代码拷贝过来,读不出数据来,showmessage是空的
      

  3.   


    procedure TPosCfg.ReadPosCfg;
    var
      tmpQuery : TADOQuery;
      str, stmp: string;
      i: Integer;
    begin
      tmpQuery := TADOQuery.Create(nil);
      tmpQuery.Connection := SysDM.GetLocalConn;//自己封装的一个连接
      try
        try
          //获得组织名称
          str := 'select OrgName from tPosOrg where OrgCode=:OrgCode';
          sOrgName := ' ';
          with tmpQuery do
          begin
            Close;
            SQL.clear;
            SQL.Add(str);
            Parameters.ParamByName('OrgCode').Value := sOrgCode;
            Open;
            if not eof then
            begin
              sOrgName := FieldByName('OrgName').AsString;
            end;
          end;      str := 'select * from ' + T_JKPOSCFG +
            ' where OrgCode=:OrgCode and  AreaCode=:PosArea and PosNo=:PosNo';
          with tmpQuery do
          begin
            Close;
            SQL.clear;
            SQL.Add(str);
            Parameters.ParamByName('OrgCode').Value := sOrgCode;
            Parameters.ParamByName('PosArea').Value := sPosArea;
            Parameters.ParamByName('PosNo').Value := sPosNo;
            Open;
            if Eof then
            begin
              ErrorMsgBox('请进入管理界面进行设置!');
            end;  
            PosCfg.sShopType := '百货';
            if Locate('funNum', 'SHOP TYPE', [loPartialKey]) then
              PosCfg.sShopType := FieldByName('CurValue').AsString;        bNet := false;
            if Locate('funNum', 'CONNECT', [loPartialKey]) then //是否联网 'YES',
              if UpperCase(FieldByName('CurValue').AsString) = 'YES' then
                bNet := True
              else
                bNet := false;        //取得iBankVipPostion, iBankVipLen, iBankVipBegin;dongyongle
            iBankVipPosition := 0;
            if Locate('funNum', 'BANKVIPPOSITION', [loPartialKey]) then
              iBankVipPosition := FieldByName('CurValue').AsInteger;        iBankVipBegin := 0;
            if Locate('funNum', 'BANKVIPBEGIN', [loPartialKey]) then
              iBankVipBegin := FieldByName('CurValue').AsInteger;        iBankVipLen := 0;
            if Locate('funNum', 'BANKVIPLEN', [loPartialKey]) then
              iBankVipLen := FieldByName('CurValue').AsInteger;
    end;
      

  4.   


    procedure TPosCfg.ReadPosCfg;
    var
      tmpQuery : TADOQuery;
      str, stmp: string;
      i: Integer;
    begin
      tmpQuery := TADOQuery.Create(nil);
      tmpQuery.Connection := SysDM.GetLocalConn;//自己封装的一个连接
      try
        try
          //获得组织名称
          str := 'select OrgName from tPosOrg where OrgCode=:OrgCode';
          sOrgName := ' ';
          with tmpQuery do
          begin
            Close;
            SQL.clear;
            SQL.Add(str);
            Parameters.ParamByName('OrgCode').Value := sOrgCode;
            Open;
            if not eof then
            begin
              sOrgName := FieldByName('OrgName').AsString;
            end;
          end;      str := 'select * from ' + T_JKPOSCFG +
            ' where OrgCode=:OrgCode and  AreaCode=:PosArea and PosNo=:PosNo';
          with tmpQuery do
          begin
            Close;
            SQL.clear;
            SQL.Add(str);
            Parameters.ParamByName('OrgCode').Value := sOrgCode;
            Parameters.ParamByName('PosArea').Value := sPosArea;
            Parameters.ParamByName('PosNo').Value := sPosNo;
            Open;
            if Eof then
            begin
              ErrorMsgBox('请进入管理界面进行设置!');
            end;  
            PosCfg.sShopType := '百货';
            if Locate('funNum', 'SHOP TYPE', [loPartialKey]) then
              PosCfg.sShopType := FieldByName('CurValue').AsString;        bNet := false;
            if Locate('funNum', 'CONNECT', [loPartialKey]) then //是否联网 'YES',
              if UpperCase(FieldByName('CurValue').AsString) = 'YES' then
                bNet := True
              else
                bNet := false;        //取得iBankVipPostion, iBankVipLen, iBankVipBegin;dongyongle
            iBankVipPosition := 0;
            if Locate('funNum', 'BANKVIPPOSITION', [loPartialKey]) then
              iBankVipPosition := FieldByName('CurValue').AsInteger;        iBankVipBegin := 0;
            if Locate('funNum', 'BANKVIPBEGIN', [loPartialKey]) then
              iBankVipBegin := FieldByName('CurValue').AsInteger;        iBankVipLen := 0;
            if Locate('funNum', 'BANKVIPLEN', [loPartialKey]) then
              iBankVipLen := FieldByName('CurValue').AsInteger;
    end;