• TStringList中AddObject使用


    结构体定义

    PYpType=^TYpType;
     TYpType=record
        yfcode:string;
        ypcode:string;
        YpUnitPrice:Currency;
        YpRetailPrice:Currency;
        YpCostPrice:Currency;
        YpTotal:Currency;
        CkTotal:Currency;
        YpUseDT:string;
        YpAddr:string;
        Dwcode:string;
        CzyCode:string;
        Update_DT:TDateTime;
        IsDelete:Integer;
        IsApprove:Integer;
     end;

    加入结构体

    function GetYfcodes: TStringList;

    var
      sTemp, sTemp1: string;
      i: Integer;
      kcTotal, ckTotal: Currency;
      YpType: PYpType;
    begin
      Result := TStringList.Create;
      if not dsDetail.IsEmpty then
      begin
        dsDetail.First;
        sTemp := '';
        sTemp1 := '';
        kcTotal := 0;
        ckTotal := 0;
        i := 0;
        while not dsDetail.Eof do
        begin
          sTemp1 := Format('%s,%s,%s,%s', [TCustomObj(cbbyf.Items.Objects[cbbyf.ItemIndex]).Code,
            dsDetail.FieldByName('YpCode').AsString,
              dsDetail.FieldByName('YpUnitPrice').AsString,
              dsDetail.FieldByName('YpRetailPrice').AsString]);
          if sTemp <> sTemp1 then
          begin
            sTemp := Format('%s,%s,%s,%s', [TCustomObj(cbbyf.Items.Objects[cbbyf.ItemIndex]).Code,
              dsDetail.FieldByName('YpCode').AsString,
                dsDetail.FieldByName('YpUnitPrice').AsString,
                dsDetail.FieldByName('YpRetailPrice').AsString]);
            if i > 0 then
            begin
              YpType^.YpTotal := kcTotal;
              YpType^.CkTotal := ckTotal;
              kcTotal := 0;
              ckTotal := 0;
              Result.AddObject(YpType^.ypcode, TObject(YpType));
              i := 0;
            end;
            New(YpType);
            YpType^.yfcode := TCustomObj(cbbyf.Items.Objects[cbbyf.ItemIndex]).Code;
            YpType^.ypcode := dsDetail.FieldByName('YpCode').AsString;
            YpType^.YpUnitPrice := dsDetail.FieldByName('YpUnitPrice').AsCurrency;
            YpType^.YpRetailPrice := dsDetail.FieldByName('YpRetailPrice').AsCurrency;
            YpType^.YpCostPrice := 0;
            YpType^.YpAddr := cbbypddr.Value;
            YpType^.YpUseDT := FormatDateTime('YYYY-MM-DD', dtyxq.Date);
            YpType^.Update_DT := Now;
            YpType^.Dwcode := TCustomObj(cbbdw.Items.Objects[cbbdw.ItemIndex]).Code;
            YpType^.IsDelete := 0;
            YpType^.IsApprove := 0;
            YpType^.CzyCode := TCustomObj(cbbczy.Items.Objects[cbbczy.ItemIndex]).Code;
          end;
          kcTotal := kcTotal + dsDetail.FieldByName('YpTotal').Value;
          ckTotal := ckTotal + dsDetail.FieldByName('CkTotal').Value;
          dsDetail.Next;
          if dsDetail.Eof then
          begin
            YpType^.YpTotal := kcTotal;
            YpType^.CkTotal := ckTotal;
            Result.AddObject(YpType^.ypcode, TObject(YpType));
          end;
          Inc(i);
        end;
      end;
    end;

    使用和释放结构体

    procedure SaveMain;

    var
      ypStr: TStringList;
      i: Integer;
      YpType: PYpType;
      FHeaderID: Integer;
    begin
      if not CheckInput then Exit;
      ypStr := GetYfcodes;
      try
        try
          for I := 0 to ypStr.Count - 1 do
          begin
            YpType :=PYpType(ypstr.Objects[i]);
            if FDataSetMode = dsEdit then
              dsMaster.Edit
            else if
              FDataSetMode = dsAdd then
              dsMaster.Append
            else
              dsMaster.Append;
            FHeaderID := GetNextId('YP_BatchMergeHeader');
            dsMaster.FieldByName('HeaderID').Value := FHeaderID;
            dsMaster.FieldByName('YfCode').Value := YpType^.yfcode;;
            dsMaster.FieldByName('YpCode').Value := YpType^.ypcode;
            dsMaster.FieldByName('YpUnitPrice').Value := YpType^.YpUnitPrice;
            dsMaster.FieldByName('YpRetailPrice').Value := YpType^.YpRetailPrice;
            dsMaster.FieldByName('YpCostPrice').Value := YpType^.YpCostPrice;
            dsMaster.FieldByName('YpTotal').Value := YpType^.YpTotal-YpType^.CkTotal;
            dsMaster.FieldByName('CkTotal').Value := 0;
            dsMaster.FieldByName('YpAddr').Value := YpType^.YpAddr;
            dsMaster.FieldByName('YpUseDT').Value := YpType^.YpUseDT;
            dsMaster.FieldByName('Update_DT').Value := YpType^.Update_DT;
            dsMaster.FieldByName('DwCode').Value := YpType^.Dwcode;
            dsMaster.FieldByName('CzyCode').Value := YpType^.CzyCode;
            dsMaster.FieldByName('IsDelete').Value := YpType^.IsDelete;
            dsMaster.FieldByName('IsApprove').Value := YpType^.IsApprove;
            dsMaster.Post;
          end;
        except
          on E: Exception do
          begin
            MyMsgBox(MsgSaveFail + ':' + e.Message);
            SetLogTxt(e.Message);
            Exit;
          end;
        end;
      finally
        //释放PYpType
        for i := 0 to ypStr.Count - 1 do
        begin
          if Assigned(ypStr.Objects[i]) then
            Dispose(PYpType(ypStr.Objects[i]));
        end;
        ypStr.Free;
      end;
    end;

  • 相关阅读:
    Linux的五个查找命令
    Linux中ftp不能上传文件/目录的解决办法
    linux下的chmod,chown和chgrp
    Memcache基础教程
    Web服务器磁盘满故障
    linux定时任务生产java服务无法执行问题案例
    Linux 用户和用户组管理
    10-xargs 简明笔记
    51-du 显示关于目录层次结构或文件磁盘使用情况的信息
    46-df 显示磁盘空间的使用情况
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/3319399.html
Copyright © 2020-2023  润新知