我之前是想在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. Android之Application类用法

    Application和Activity,Service一样是Android框架的一个系统组件,当Android程序启动时系统会创建一个Application对象,用来存储系统的一些信息. Andro ...

  2. 详细的nginx.conf中文资料整理

    整理来源: https://blog.csdn.net/tjcyjd/article/details/50695922 整理结果 Nginx的配置文件nginx.conf配置详解如下: #Nginx用 ...

  3. 几大PHP套件

    UPUPW:http://www.upupw.net/ PHPStudy:http://www.phpstudy.net/ PHPNow:http://servkit.org/

  4. 使用VS2017 编写Linux系统上的Opencv程序

    背景 之前写图像算法的程序都是在window10下使用VS编写,VS这个IDE结合“ImageWatch.vsix“插件,用于调试opencv相关的图像算法程序十分方便.后因项目需要,需将相关程序移植 ...

  5. java代码实现鼠标双击出现画图-----------paint()方法由系统自动调用,且一定是小写的字母p

    总结:在运行过程中,自己不是很认真,没有检查自己写的代码,结果是无论你怎么运行,双击 frame都没用,因为系统根本就没有调用paint()方法绘图.所以很重要的是实现这个方法 package com ...

  6. Vue.js:安装

    ylbtech-Vue.js:安装 1.返回顶部 1. Vue.js 安装 1.独立版本 我们可以在 Vue.js 的官网上直接下载 vue.min.js 并用 <script> 标签引入 ...

  7. 小记一次mysql启动失败没有日志的处理

    本来mysql好的,之前清理了一次tmp下的东西,mysql在查询的时候提示: Can't create/write to file '/tmp/ib0n3frL 然后停止启动: [root@sevc ...

  8. Lambda语句中创建自定义类型时,也可指定某种特定类型,方法是在new与{}之间写上类型名称

    如: var fc =...ChildFath = fc.Select(c => new Child_Father { child = c.child, father = c.father }) ...

  9. spark编译安装 spark 2.1.0 hadoop2.6.0-cdh5.7.0

    1.准备: centos 6.5 jdk 1.7 Java SE安装包下载地址:http://www.oracle.com/technetwork/java/javase/downloads/java ...

  10. cxf和axis2使用有感

    CXF框架 个人不喜欢使用wsimport工具: 1.考虑到远端的服务接口发生变化,本地的接口还需要重新同步下 2.项目中无端多了些冗余的代码 这样我们选择cxf的动态调用接口吧,使用DynamicC ...