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;
TStringList中AddObject使用的更多相关文章
- 删除delphi组件TStringlist中的重复项目
https://blog.csdn.net/ozhy111/article/details/87975663 删除delphi组件TStringlist中的重复项目 2019年02月27日 15:41 ...
- Delphi中根据分类数据生成树形结构的最优方法
一. 引言: TreeView控件适合于表示具有多层次关系的数据.它以简洁的界面,表现形式清晰.形象,操作简单而深受用户喜爱.而且用它可以实现ListView.ListBox所无法实现的很多功能 ...
- 教程-TObjectList.Clear、TStringList.Clear方法对象有没有被释放
相关资料: http://www.cnblogs.com/rogge7/p/4631796.html delphiTStringList通过AddObject方法添加对象. object里存的只是指向 ...
- TStringList的Find,IndexOf和Sort
procedure TForm1.Button1Click(Sender: TObject); var MyList: TStringList; begin MyList := TStringList ...
- Delphi : TStringList的Find,IndexOf和Sort
关键:Find要事先Sort排序,Indexof不用排序. TStringList内部查找相关的数据.待调试代码时才知道痛苦,浪费无数时间后,只得一步步跟踪,才发 现Find方法返回的Index总是错 ...
- DBAccess
01.单SQL执行.DBA.ExeuteSQL(SQL语句,是否返回值,是否事务处理,返回值<字符型>):Boolean; -- 执行SQL后,将影响的行数进行返回 02.批量SQL执行. ...
- cocos2d-x 2.0 序列帧动画 深入分析
转自:http://blog.csdn.net/honghaier/article/details/8222401 序列帧动画主要有几个类: CCSpriteFrame:精灵帧信息,序列帧动画是依靠多 ...
- Delphi TcxTreeList 怎们显示下拉列表
TcxTreeList 怎们显示下拉列表, 操作如下: 1.定义一个TStringlist中存储你的信息. 2.然后选定在TcxTreeList的哪个列要变成TCombobox, 如下图: 3. ...
- Mybatis,Spring,SpringMVC框架面试题
Mybatis测试 1, Mybatis的核心是( sqlsessionfactory ) 2, 使用Mybatis持久化框架进行数据查询需要返回的一个实体类的集合, 在<sel ...
随机推荐
- Microsoft Visual Studio 2010 VSTS单元测试指南
本来以为很简单的一个问题,今天预计10分钟搞定,结果到下班还没弄出结果,单元测试运行的时候一直处于无反应状态,最后估计可能是我装的2010有问题,结果到家一试果然是有问题,有时软件就是这么神奇. 言归 ...
- Mysql --分区表(2)
分区类型 RANGE分区 range分区的表是利用取值范围将数据分成分区,区间要连续并且不能互相重叠,使用values less than操作符进行分区定义 LIST分区 LIST分区是建立离散的值列 ...
- 理解POCO
理解POCO(Plain Old CLR Object)先要理解POJO. 1.什么是POJO? POJO的名称有多种,pure old java object .plain ordinary jav ...
- 删除xcode中的描述文件的路径
打开Finder commend + shift +g 进入文件夹 : ~/Library/MobileDevice/Provisioning Profiles 删除即可
- Install Solr+tomcat
1. chose the release you want: http://archive.apache.org/dist/lucene/solr/. 1) copy [solr_home]/dist ...
- windows小技巧 从文件夹直接打开命令行位置
windows下从命令行打开某个目录下的东东时,会一直cd ~~~~,更简单的是: 直接用鼠标找到该文件夹或者文件,按住Shift键然后点击鼠标右键,选择"在此处打开命令行"即可 ...
- JBoss 系列四十八:JBoss 7/WildFly 使用TCP构建集群
我知道JBoss 集群Default 的设定就是UDP(JGroups),但在实际环境中的网络环境时常不允许UDP,在这种情况下,我们就需要使用TCP. JBoss 7/WildFly 中负责集群的主 ...
- [转]Python程序员必须知道的30条编程技巧
30 tips & tricks for Python Programming 1 直接交换两个数字位置 x, y = 10, 20 print(x, y) x, y = y, x prin ...
- [ASE][Daily Scrum]11.25
View Shilin Liu 修复现有的bug,子弹无法破坏射程内视野外的墙 Yiming Liao 无法看见从视野外到视野内的子弹 Server Songtao He 服务器处理子弹命中t ...
- MongoDB安装及shell简介
MongoDB安装 MongoDB具有跨平台的优良特性,提供了对主流的操作系统支持,我们可以根据自己使用的操作系统,选择下载对应的安装包. 图 1. MongoDB支持各个版本的操作系统 MongoD ...