结构体定义

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;

TStringList中AddObject使用的更多相关文章

  1. 删除delphi组件TStringlist中的重复项目

    https://blog.csdn.net/ozhy111/article/details/87975663 删除delphi组件TStringlist中的重复项目 2019年02月27日 15:41 ...

  2. Delphi中根据分类数据生成树形结构的最优方法

    一. 引言:    TreeView控件适合于表示具有多层次关系的数据.它以简洁的界面,表现形式清晰.形象,操作简单而深受用户喜爱.而且用它可以实现ListView.ListBox所无法实现的很多功能 ...

  3. 教程-TObjectList.Clear、TStringList.Clear方法对象有没有被释放

    相关资料: http://www.cnblogs.com/rogge7/p/4631796.html delphiTStringList通过AddObject方法添加对象. object里存的只是指向 ...

  4. TStringList的Find,IndexOf和Sort

    procedure TForm1.Button1Click(Sender: TObject); var MyList: TStringList; begin MyList := TStringList ...

  5. Delphi : TStringList的Find,IndexOf和Sort

    关键:Find要事先Sort排序,Indexof不用排序. TStringList内部查找相关的数据.待调试代码时才知道痛苦,浪费无数时间后,只得一步步跟踪,才发 现Find方法返回的Index总是错 ...

  6. DBAccess

    01.单SQL执行.DBA.ExeuteSQL(SQL语句,是否返回值,是否事务处理,返回值<字符型>):Boolean; -- 执行SQL后,将影响的行数进行返回 02.批量SQL执行. ...

  7. cocos2d-x 2.0 序列帧动画 深入分析

    转自:http://blog.csdn.net/honghaier/article/details/8222401 序列帧动画主要有几个类: CCSpriteFrame:精灵帧信息,序列帧动画是依靠多 ...

  8. Delphi TcxTreeList 怎们显示下拉列表

    TcxTreeList  怎们显示下拉列表, 操作如下: 1.定义一个TStringlist中存储你的信息. 2.然后选定在TcxTreeList的哪个列要变成TCombobox,  如下图: 3. ...

  9. Mybatis,Spring,SpringMVC框架面试题

    Mybatis测试 1,   Mybatis的核心是(  sqlsessionfactory    ) 2,   使用Mybatis持久化框架进行数据查询需要返回的一个实体类的集合, 在<sel ...

随机推荐

  1. 几个与特殊字符处理有关的PHP函数

    函数名 释义 介绍 htmlspecialchars 将与.单双引号.大于和小于号化成HTML格式 &转成&"转成"' 转成'<转成<>转成> ...

  2. ubuntu搭建svn服务器(转)

    在阿里云买了个服务器,想上传东西,samba不好用,想起来可以搭个svn用,找到了这篇. 1. 安装SVN apt-get install subversion 2. 建立svn仓库 1). 建立sv ...

  3. C# 图片盖章功能实现,支持拖拽-旋转-放缩-保存

    实现图片盖章功能,在图片上点击,增加“图章”小图片,可以拖拽“图章”到任意位置,也可以点击图章右下角园框,令图片跟着鼠标旋转和放缩. 操作方法:1.点击增加“图章”2.选中移动图标3.点中右下角放缩旋 ...

  4. 从“程序员转行卖烧饼”想到IT人创业

    我的一个朋友最近总在跟我念叨着“我不想做开发了,整天累死累活写程序,也攒不下几个钱.我想辞职搞点啥!” 我问他:“你想搞点啥?”. 他说:“搞啥都比做开发强,做个网站赚广告费,接私活……实在不行我去卖 ...

  5. ftp客户端命令使用简记

    OS:windows8.1评估版 程序和功能 tftp客户端勾选上 Win+R:运行,键入cmd,键入ftp -help 如下图: 使用ftp客户端可以做的事:将文件传送到运行FTP服务器服务(经常称 ...

  6. starUML使用教程

    starUML使用教程 下载与安装 先从官网下载软件,这个版本是收费的,但可以先进行试用.也可以使用免费版,基本UML依然齐全,但用起来感觉没有收费版好用. 下载之后按照安装说明,一步步安装就可以了. ...

  7. modelbinder机制原理

    ModelBinder介绍 一.问题描述 当运行一个Mvc时,你控制器中的Action方法需要参数数据:而这些参数数据包含在HTTP请求中,包括表单上的Value和URL中的参数等.但问题是控制器中的 ...

  8. JAVA面试精选【Java基础第一部分】

    这个系列面试题主要目的是帮助你拿轻松到offer,同时还能开个好价钱.只要能够搞明白这个系列的绝大多数题目,在面试过程中,你就能轻轻松松的把面试官给忽悠了.对于那些正打算找工作JAVA软件开发工作的童 ...

  9. MySql获取表的字段名称、字段注解、字段类型、字段长度

    SELECT  COLUMN_NAME as '列名',COLUMN_COMMENT,DATA_TYPE as '字段类型' ,COLUMN_TYPE as '长度加类型' FROM informat ...

  10. 字符串匹配算法之SimHash算法

    SimHash算法 由于实验室和互联网基本没啥关系,也就从来没有关注过数据挖掘相关的东西.在实际工作中,第一次接触到匹配和聚类等工作,虽然用一些简单的匹配算法可以做小数据的聚类,但数据量达到一定的时候 ...