TStringList中AddObject使用

简介: 结构体定义 PYpType=^TYpType; TYpType=record    yfcode:string;    ypcode:string;    YpUnitPrice:Currency;    YpRetailPrice:Currency;    YpCostPrice:Currenc...

结构体定义

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;

目录
打赏
0
0
0
0
10
分享
相关文章
幻兽帕鲁Palworld服务器部署教程,阿里云3分钟保姆手把手教程
幻兽帕鲁Palworld服务器部署教程,阿里云3分钟保姆手把手教程,玩转幻兽帕鲁服务器,阿里云推出新手0基础一键部署幻兽帕鲁服务器教程,傻瓜式一键部署,3分钟即可成功创建一台Palworld专属服务器,成本仅需26元,阿里云百科网分享2024年新版基于阿里云搭建幻兽帕鲁服务器教程
359 0
Flink CDC MySQL同步MySQL错误记录
在使用Flink CDC同步MySQL数据时,常见的错误包括连接错误、权限错误、表结构变化、数据类型不匹配、主键冲突和
351 17
|
11月前
|
智能家居安全漏洞分析与防护策略
随着物联网技术的快速发展,智能家居系统已成为现代生活的一个趋势。然而,随之而来的安全问题也日益突出。本文将深入探讨智能家居系统中存在的安全漏洞,并针对性地提出一系列有效的防护措施。通过实际案例分析,旨在提升用户的安全防护意识,确保智能家居环境的安全性和可靠性。
185 27
深入探讨前后端之争:揭秘Go语言在未来全栈Web开发中的关键角色与价值
深入探讨前后端之争:揭秘Go语言在未来全栈Web开发中的关键角色与价值
227 0
MyBatis-Plus更新部分字段
MyBatis-Plus更新部分字段
1208 0
【蓝桥杯集训·每日一题】 AcWing 3996. 涂色
文章目录 一、题目 1、原题链接 2、题目描述 二、解题报告 1、思路分析 2、时间复杂度 3、代码详解 三、知识风暴 区间DP Unique函数
157 0
HTML中图片和文字按照上下排列并且水平居中显示
HTML中图片和文字按照上下排列并且水平居中显示
357 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问