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 ...
随机推荐
- Vrapper-Eclipse的vim插件安装方法
Vrapper是一款Eclipse的插件,使在Eclipse下编辑文档时可以像使用Vim一样. 它有两种安装方法,在线安装和安装包安装: 在线安装: 打开Eclipse,Help->Instal ...
- 利用Apache Ant编译Hadoop2.6.0-eclipse-plugin
环境要求:系统不重要,重要的是要有Ant环境,这里不做赘述,自行百度配置去. 1)在github上下载Hadoop-eclipse-plugin-master的zip包,下载地址. 2)在Hadoop ...
- Myeclipse加载maven
1.自带,需要将之前下好的文本加入到myeclipse中即可.windows---->preference---->Myeclipse---->MavenMyeclipse 3.将本 ...
- Android性能优化方法(六)
ContentProvider优化改进 1.索引简单的说,索引就像书本的目录,目录可以快速找到所在页数,数据库中索引可以帮助快速找到数据,而不用全表扫描,合适的索引可以大大提高数据库查询的效率.(1) ...
- (原创)即使最可怕的自然力量,也不失美丽——火山喷发(摄影,欣赏)
文中图片摘自腾讯文化:www.cal.qq.com 1.Abstract 最可怕的力量也潜含着最美丽的风景奇观,虽然不能亲眼目睹,但透过大师的视角,一样也能体会到自然力量撼动的美丽. 2.Co ...
- 让IE支持placeholder属性~
原文:https://www.oschina.net/code/snippet_206691_26471#44160 让支持的直接路过,不支持的,完美显示~~ /* * jQuery placeho ...
- SQL语句汇总(二)——数据修改、数据查询
首先创建一张表如下,创建表的方法在上篇介绍过了,这里就不再赘述. 添加新数据: INSERT INTO <表名> (<列名列表>) VALUES (<值列表>) ...
- 手机H5 web调试利器——WEINRE (WEb INspector REmote)
手机H5 web调试利器--WEINRE (WEb INspector REmote) 调试移动端页面,优先选择使用chrome浏览器调试,如果是hybrid形式的页面,可以使用chrome提供的ch ...
- Openstack Murano(kilo)二次开发之添加Volume
Openstack Murano(kilo)二次开发之添加Volume 欢迎转载,转载请注明出处:http://www.cnblogs.com/fmnisme/p/openstack_murano_a ...
- servlet web文件上传
web文件上传也是一种POST方式,特别之处在于,需设置FORM的enctype属性为multipart/form-data. 并且需要使用文件域. servlet的代码比较关键是这几句: // 使用 ...