XE中FMX操作ListBox,添加上千条记录(含图片)
我之前是想在ListBox的每个Item上添加一个图片,Item上所有的内容都是放在Object里赋值,结果发现加载一百条记录耗时四五秒:
procedure TMainForm.AddItem;
var
o : TListBoxItem;
o1 : TFrm;
begin
o := TListBoxItem.Create(self); // 创建对象
o.Height := 128;
o1 :=TFrm.Create(o); // 创建TFrm
o1.Parent:=o;
ListBox1.AddObject(o);
end; var
s, temp: string;
x: IMember;
begin
if FJV <> Value then begin
FJV := Value;
for x in Value do begin // x为遍历所有Item框架上的组件的值
s := x.AsString;
if x.Name = 'IPNR' then IPNR .Text := s else
if x.Name = 'IPNColor' then IPNColor .Text := s else
if x.Name = 'ITime' then ITime .Text := s else
if x.Name = 'OTime' then OTime .Text := s else
if x.Name = 'PName' then PName .Text := s else
if x.Name = 'IGateName' then IGateName.Text := s else
if x.Name = 'OGateName' then OGateName.Text := s else
if x.Name = 'IMobileNo' then IMobileNo.Text := s else
if x.Name = 'State' then timer1.Enabled := True;
;
end;
end;
这里加载图片,我还是用线程异步加载的,速度还是不行:
procedure TMainForm.DrawImg();
var
i: integer;
o: TImage;
fn:string;
begin
// 取
TThread.CreateAnonymousThread(procedure var y : IMember; begin
i:=length(bmps);
if(i<>FNs.Count)and(FNs.Count>0) then begin
SetLength(bmps,FNs.Count);
for y in FNs do if y.AsInteger=-1 then begin
bmps[i]:=TBitmap.CreateFromFile(y.Name);
FNs.I[y.Name]:=i;
inc(i);
end;
end;
// 显示
TThread.Synchronize(TThread.CurrentThread, procedure var z: IMember; begin
i:=0;
for z in JV do begin
o :=TFrm(ListBox1.ListItems[i].FindComponent('Frm')).Image1;
fn:=z.AsObject.S['IImagePath'];
o.Visible := FNs.Contains(fn);
if(o.Visible) then o.Bitmap.Assign(bmps[FNs.I[fn]]);
inc(i);
end;
end);
end).Start;
end;
然后我将图片压缩,压缩后倒是快了那么一两秒,但是如果数据量大的话,还是有很明显的延迟效果:
uses Vcl.Imaging.jpeg;
{fn1为压缩前的图片路径,fn2为压缩后的图片路径}
procedure CutImg(fn1:string; fn2:string);
var
jpg: TJpegImage;
bmp: TBitmap;
begin
jpg := TJpegImage.Create;
bmp := TBitmap.Create;
try
if FileExists(fn1) then begin
jpg.LoadFromFile(fn1);
if jpg.Width > 320 then begin
bmp.Width := 320; //jpg.Width; 经测试的宽度
bmp.Height:= 256; //jpg.Height;
bmp.Canvas.StretchDraw(bmp.Canvas.ClipRect, jpg);
jpg.Assign(bmp);
jpg.CompressionQuality := 30;
jpg.Compress; //压缩
jpg.SaveToFile(fn2);
end;
end;
finally
bmp.Free;
jpg.Free;
end;
end;
最后通过别人那里知道XE中ListBox有style模板,看XE自带的原码,目录在C:\Users\Public\Documents\Embarcadero\Studio\14.0\Samples\Object Pascal\FireMonkey Desktop\CustomListBox\CustomListBox.dpr;
这个例子就是导入一千条记录,简直就只需要一秒,速度太快了,XE支持这个功能真是太好了。然后我把之前的框架换成了style(style用XE6还是有很多bug的,后来我换成了XE8,这里自己摸),速度提高了几倍:
for x in jo do with item do begin
s := x.AsString.Replace('/', '\');
if x.Name = 'IPNR' then StylesData['IPNR.Text' ] := s else
if x.Name = 'IPNColor' then StylesData['IPNColor.text' ] := s else
if x.Name = 'ITime' then StylesData['ITime.text' ] := s else
if x.Name = 'OTime' then StylesData['OTime.text' ] := s else
if x.Name = 'PName' then StylesData['PName.text' ] := s else
if x.Name = 'IGateName' then StylesData['IGateName.text' ] := s else
if x.Name = 'OGateName' then StylesData['OGateName.text' ] := s else
if x.Name = 'IMobileNo' then StylesData['IMobileNo.text' ] := s else
if x.Name = 'IImagePath' then if s <> '' then StylesData['Image1.Bitmap' ] := bmps[s] else
bmps为TDictionary<string, TBitmap>类;需要uses Generics.Collections;
这是泛型,存放一个key,和key对应的Value:
t:=1; o:=FileToStream('c:/123.jpg');
bmps.Add(t, o);
取值时为 Image1.Bitmap := bmps[s]
这样简单了很多,少了很多代码,快了很多时间。
XE中FMX操作ListBox,添加上千条记录(含图片)的更多相关文章
- jsp如何判断mysql数据库中是否已经存在添加的某条记录的方法
String query="select * from hdxcy_info where XcyName='"+XcyName+"'"; String sqlS ...
- 清理8组nodes中表的历史数据,平均每个node中的表有1.5亿条记录,需要根据date_created字段清理8000W数据记录,这个字段没有索引。
清理8组nodes中表的历史数据,平均每个node中的表有1.5亿条记录,需要根据date_created字段清理8000W数据记录,这个字段没有索引. 环境介绍 线上磁盘空间不足,truncate ...
- sql查询上一条记录和下一条记录
上一条记录的SQL语句: * from news where newsid<id order by newsid DESC 下一条记录的SQL语句: * from news where news ...
- MySQL查询上一条记录和下一条记录
如果ID是主键或者有索引,可以直接查找: 方法一: 查询上一条记录的SQL语句(如果有其他的查询条件记得加上other_conditions以免出现不必要的错误): select * from tab ...
- [转]SQL中 OVER(PARTITION BY) 取上一条,下一条等
OVER(PARTITION BY)函数介绍 开窗函数 Oracle从8.1.6开始提供分析函数,分析函数用于计算基于组的某种聚合值,它和聚合函数的不同之处是:对于每个组返 ...
- MVC批量添加,增加一条记录的同时添加N条集合属性所对应的个体
类别中包含一个产品的集合属性,如何向数据库添加一条类别记录的同时,添加任意多个产品. public class Product { [DisplayName("产品名称")] pu ...
- 将Excel上千条数据写入到数据库中
简要说明:因工作需要,需要一张Excel表格中的所有数据导入到数据库中.如下表,当然这只是一部分,一共一千多条. 前期处理: 首先要保证上图中的Excel表格中的数据不能为空,如果有为空的数据,可以稍 ...
- iview 如何在表格中给操作图标添加Tooltip文字提示?
项目需要用到的iview 表格中操作项目有各种各样的图标,而各种各样的图标代表不同的操作,面对新用户可能很懵,那如何给这些图标添加Tooltip文字提示? 废话不多讲,直接看代码: <templ ...
- Unity中使用RequireComponent,没有添加上组件
using UnityEngine; using System.Collections; [RequireComponent(typeof(MeshFilter), typeof(MeshRender ...
随机推荐
- Ajax验证用户名
用Ajax验证用户名: 接口: get guestbook/index.php m : index a : verifyUserName username : 要验证的用户名 返回 { code : ...
- 安装并配置工具以使用iOS进行构建
Visual Studio 2015 Visual Studio文档的新家是docs.microsoft.com上的Visual Studio 2017文档 . 有关Visual Studio 2 ...
- HTML注册页面验证注册信息
在这里主要介绍两种验证方式,一种是点击注册按钮后会提示最上方的出错位置,弹出窗口提示格式不对.另一种是利用鼠标事件,在鼠标进行不同操作时会有不同的click事件. 这两种都是利用javascript, ...
- 字符串转换为字典的函数eval(字符串)
首先把多行的字符串,变成一个字符串,用'''和'''扩起来: 然后把这个字符串,赋值给b 这个时候,b根本调不出来,也用不起来: 用eval(b),来格式化字符串变成字典: 然后b就变成了一个字典:
- 012. MVC5中Razor引擎使用模板页
1.文件→新建项目→框架选择.NET Framework 4.5 2.确定后选择ASP.NET 4.5 模板→MVC→为以下项添加文件夹和核心引用→MVC, 在vs 2015中默认就使用的Razor引 ...
- mac下自定义伪协议配置
之前查了很多资料,最近也在挖掘研究这方面的漏洞. windows的很简单,在注册表配置就好了,但是mac os 是unix的,没有注册表这么一说. 但是发现腾讯等配置了自定义等协议,例如:tencen ...
- transfrom-runtime文档
transfrom-runtime文档 babel只会默认对句法进行转换,而那些方法,api不会转换,要转就要使用polyfill和transform,这里介绍transform,关于polyfill ...
- C#应用调试C++ dll的方法
最近碰到个C#应用闪退的问题,由于通讯部分调用了C++工程写的dll,下面介绍一种调试的方法. 右键 启动项目,分别配置常规和和调试即可,如下图. 常规中,输出目录设置为安装目录中dll对应的目录: ...
- leetcode598
public class Solution { public int MaxCount(int m, int n, int[,] ops) { ); ); || col == ) { return m ...
- aop计算方法耗时
package necs.omms.common.aop; import lombok.extern.apachecommons.CommonsLog;import org.apache.common ...