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 ...
随机推荐
- struts2的result的type属性
一共有两个属性name和type name这里就不介绍了 type 返回结果的类型,值可以从default-struts.properties中看到看到 常用的值:dispatcher (默认) ...
- 【Java学习笔记】<集合框架>对字符串进行长度排序
package 测试; import java.util.Comparator; public class ComparatorByLength implements Comparator { //定 ...
- PHP 使用CURL
CURL是一个非常强大的开源库,支持很多协议,包括HTTP.FTP.TELNET等,我们使用它来发送HTTP请求.它给我 们带来的好处是可以通过灵活的选项设置不同的HTTP协议参数,并且支持HTTPS ...
- node-restify简介
restify 是Node.js的模块.虽然restify的API或多或少的参考了express,但restify不是一个MVC框架,它是一套为了能够正确构建REST风格API而诞生的框架. ###安 ...
- 禁用 WebView 放大镜及拷贝粘贴弹出框
文/KyXu(简书作者)原文链接:http://www.jianshu.com/p/40048d9c979a著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 背景:当你的App中有 We ...
- Deis logo 开源PaaS系统 Deis
Deis 是一个 Django/Celery API 服务器.Python CLI 和一组 Chef cookbooks 合并起来提供一个类似 Heroku 的应用平台,用于公有云和私有云.Deis ...
- 随机数是骗人的,.Net、Java、C为我作证
几乎所有编程语言中都提供了"生成一个随机数"的方法,也就是调用这个方法会生成一个数,我们事先也不知道它生成什么数.比如在.Net中编写下面的代码: Random rand = ne ...
- 学习WPF——了解路由事件
入门 我们先来看一个例子 前台代码: 后台代码: 点击按钮的运行效果第一个弹出窗口 第二个弹出窗口: 第三个弹出窗口: 说明 当点击按钮之后,先触发按钮的click事件,再上查找,发现stackpan ...
- ViEmuVS2013-3.2.1 破解
VS升级到2013后,作为一个Vimer,自然需要更新最新的ViEmu插件,因为现在离了Vim,写代码已经寸步难行了. ViEmu 3.2.1的破解其实和Viemu 3.0.13的破解方法一样.安装前 ...
- Wijmo 2016 V2 强势发布!
Angular 2 支持 Wijmo 对 Angular 2 提供了全面的支持.我们一直在紧跟Angular 2 开发团队的步伐,对其发布的最新候选版本提供支持. 了解更多关于Angular 2 的支 ...