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 ...
随机推荐
- [[4], [5, 6, 7]](Python)list的方法
现在我们要学习一些Python的数据结构了,本节将主要学习列表(list)的用法 1.list的方法 list.append(x) 在list的末尾添加一个元素 >>> a=[1,2 ...
- github 仓库管理
一.远程仓库有master和dev分支1. 克隆代码 git clone https://github.com/master-dev.git # 这个git路径是无效的,示例而已 2. 查看所有分支 ...
- 一些gem的简要翻译(欢迎提出问题共同讨论)
写这篇文章主要有两方面用途 1.希望给rails同行一定的帮助,翻译水平有限,贴出中英文,翻译有误的地方欢迎指正,非常感谢,转载请标明出处,谢谢. 2.加深作者对gem的理解,有需要更详细了解安装以及 ...
- 第35讲:List的map、flatMap、foreach、filter操作代码实战
List类的高阶方法 val fmap = List( 1,2 ,3). map { _ + 1 } //List(2, 3, 4) val fruit_rev2 = frui ...
- pm2使用介绍
https://segmentfault.com/a/1190000002539204
- Request Tracker 4.0.13 发布
Request Tracker 4.0.13 修复了几个重要的安全问题. Request Tracker,企业级的问题跟踪系统
- mssql的日期函数,如何取得当前年月日,当前时间,当前月份,当前天数,一年中第几天?
mssql函数DATENAME 语法 DATENAME ( datepart , date ) 参数 datepart 是返回的 date 的一部分.下表列出了所有有效的 datepart 参数.用户 ...
- Windows上成功编译CoreCLR源代码
昨天得知微软在GitHub上发布CoreCLR的源代码之后,立马从GitHub上签出代码,并尝试在Windows Server 2012上进行编译. 参考CoreCLR的开发者指南(Developer ...
- xampp连接Admin界面报错
报错信息: phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You s ...
- UnicodeDecodeError while using json.dumps()
UnicodeDecodeError 系统.文件.vim全部设置为utf-8 export LANG=zh_CN.UTF8 # coding:utf-8 json.dumps(content, ens ...