结构体定义

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. (Python )控制流语句if、for、while

    这一节,我们将学习Python的控制流语句,主要包括if.for.while.break.continue 和pass语句 1. If语句 if语句也许是我们最熟悉的语句.其使用方法如下: x=inp ...

  2. Ubuntu终端Terminal常用快捷键

    快捷键 功能 Tab 自动补全 Ctrl+a 光标移动到开始位置 Ctrl+e 光标移动到最末尾 Ctrl+k 删除此处至末尾的所有内容 Ctrl+u 删除此处至开始的所有内容 Ctrl+d 删除当前 ...

  3. 从原生APK反编译,拿到界面,用于mono for android

    从原生APK反编译,拿到界面,用于mono for android 1.用apktool反编译apk,得到xxx.apk.de 2.从xxx.apk.de\res\layout 3.复制所有xml到M ...

  4. 临时表VS表变量--因地制宜,合理使用

    一直以来大家对临时表与表变量的孰优孰劣争论颇多,一些技术群里的朋友甚至认为表变量几乎一无是处,比如无统计信息,不支持事务等等.但事实并非如此.这里我就临时表与表变量做个对比,对于大多数人不理解或是有歧 ...

  5. 利用扩展事件(Xevents)捕捉高消耗查询

    生产环境中有时需要使用者抓取一些特定的语句分析,如超超长查询,或高IO查询等.一般来说大家对跟踪比较熟悉,主要因为其有完善的UI支持.由于扩展事件在sql2012才提供UI支持,所以虽然在08时就已经 ...

  6. SQL Server 事务语法

    事务全部是关于原子性的.原子性的概念是指可以把一些事情当做一个单元来看待.从数据库的角度看,它是指应全部执行或全部都不执行的一条或多条语句的最小组合. 为了理解事务的概念,需要能够定义非常明确的边界. ...

  7. 2.利用NABCD模型进行竞争性需求分析

    1) N (Need 需求) 在宿舍里,舍友下载了一个比较好玩的游戏,一块好看的电影或者共享一个大体积的文件,而你又不想去重新下载,于是乎:‘’哎,win8怎么共享?‘’,‘’我的网上邻居怎么看不到你 ...

  8. SQL——系统函数

    1) CASE CASE有两种使用形式:一种是简单的CASE函数,另一种是搜索型的CASE函数. [1]简单的 CASE 函数 Format: CASE input_expression WHEN w ...

  9. [Python爬虫] Selenium获取百度百科旅游景点的InfoBox消息盒

    前面我讲述过如何通过BeautifulSoup获取维基百科的消息盒,同样可以通过Spider获取网站内容,最近学习了Selenium+Phantomjs后,准备利用它们获取百度百科的旅游景点消息盒(I ...

  10. Android动画及图片的缩放和旋转

    Android动画有2种,一种是Tween Animation,另一种是Frame Animation,先说说Tween动画吧. Tween动画是对视图对象中的内容进行一系列简单的转换,比如位置的移动 ...