我之前是想在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,添加上千条记录(含图片)的更多相关文章

  1. jsp如何判断mysql数据库中是否已经存在添加的某条记录的方法

    String query="select * from hdxcy_info where XcyName='"+XcyName+"'"; String sqlS ...

  2. 清理8组nodes中表的历史数据,平均每个node中的表有1.5亿条记录,需要根据date_created字段清理8000W数据记录,这个字段没有索引。

    清理8组nodes中表的历史数据,平均每个node中的表有1.5亿条记录,需要根据date_created字段清理8000W数据记录,这个字段没有索引. 环境介绍  线上磁盘空间不足,truncate ...

  3. sql查询上一条记录和下一条记录

    上一条记录的SQL语句: * from news where newsid<id order by newsid DESC 下一条记录的SQL语句: * from news where news ...

  4. MySQL查询上一条记录和下一条记录

    如果ID是主键或者有索引,可以直接查找: 方法一: 查询上一条记录的SQL语句(如果有其他的查询条件记得加上other_conditions以免出现不必要的错误): select * from tab ...

  5. [转]SQL中 OVER(PARTITION BY) 取上一条,下一条等

    OVER(PARTITION BY)函数介绍 开窗函数               Oracle从8.1.6开始提供分析函数,分析函数用于计算基于组的某种聚合值,它和聚合函数的不同之处是:对于每个组返 ...

  6. MVC批量添加,增加一条记录的同时添加N条集合属性所对应的个体

    类别中包含一个产品的集合属性,如何向数据库添加一条类别记录的同时,添加任意多个产品. public class Product { [DisplayName("产品名称")] pu ...

  7. 将Excel上千条数据写入到数据库中

    简要说明:因工作需要,需要一张Excel表格中的所有数据导入到数据库中.如下表,当然这只是一部分,一共一千多条. 前期处理: 首先要保证上图中的Excel表格中的数据不能为空,如果有为空的数据,可以稍 ...

  8. iview 如何在表格中给操作图标添加Tooltip文字提示?

    项目需要用到的iview 表格中操作项目有各种各样的图标,而各种各样的图标代表不同的操作,面对新用户可能很懵,那如何给这些图标添加Tooltip文字提示? 废话不多讲,直接看代码: <templ ...

  9. Unity中使用RequireComponent,没有添加上组件

    using UnityEngine; using System.Collections; [RequireComponent(typeof(MeshFilter), typeof(MeshRender ...

随机推荐

  1. php通过时间戳处理时间!

    1.获取当前时间方法date() 很简单,这就是获取时间的方法,格式为:date(format,format,timestamp),format为格式.timestamp为时间戳–可填参数. 2.获取 ...

  2. 【转】CentOs中Apache开启rewrite模块详解

    rewrite是apache环境的一个伪静态功能了,如果我们没有没让Apache开启rewrite功能,网站上所有的rewrite规则都不可使用. centos的配置文件放在: /etc/httpd/ ...

  3. PHP中的use、命名空间的理解

    看.Net中的命名空间和using using Ddd.Core; using Ddd.Core.Caching; using Ddd.Core.Data; using Ddd.Core.Domain ...

  4. 第一章 走进Java(待续)

    ·········

  5. Hadoop的HA机制

    前言:正式引入HA机制是从hadoop2.0开始,之前的版本中没有HA机制 1. HA的运作机制 (1)hadoop-HA集群运作机制介绍 所谓HA,即高可用(7*24小时不中断服务) 实现高可用最关 ...

  6. SerialPort缓冲区

    SerialPort缓冲区中有:接收缓冲区,发送缓冲区,输入缓冲区,输出缓冲区,传输缓冲区. 例如: 串口属性:BytesToRead(获取接收缓冲区中数据的字节数)--这里提到的是“接收缓冲区” 串 ...

  7. Document.location.href和.replace的区别

    转自:https://www.cnblogs.com/GT_Andy/archive/2007/10/31/1922138.html 1 Document.location.href和.replace ...

  8. Apache Shiro 权限框架

    分享一个视屏教程集合 http://www.tudou.com/home/konghao/item 1.Shiro Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码 ...

  9. winform 如何正确的获取窗体的标题栏高度

    最近我需要知道鼠标在一个控件里的相对位置,鼠标相对于屏幕的位置我是可以知道的,所以只要得到控件相对于屏幕的位置,就可以算出鼠标相对于控件的位置了 但是发现有误差 后来经过测试是由于窗体的标题栏高度导致 ...

  10. 如何解决quartz在集群下出现的资源抢夺现象

    Quartz是一个开源的作业调度框架,它完全由Java写成,并设计用于J2SE和J2EE应用中.它提供了巨大的灵活性而不牺牲简单性.你能够用它来为执行一个作业而创建简单的或复杂的调度,简单的说就是可以 ...