我之前是想在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. [教程]centos卸载、安装mysql(源码编译安装方式)

    -----------1 卸载系统自带的msyql包 rpm -qa|grep mysql rpm -e --nodeps mysql-server-5.1.71-1.el6.x86_64 --强制卸 ...

  2. OpenLiveWriter 这篇文章使用博客客户端撰写

    OpenLiveWriter是非常方便的博客客户端,起码相比在浏览器写博客多了一种选择.而且借助于MetaWeblog接口,可以很方便地同步博客文章到多个博客地址.本站cms.xlongwei.com ...

  3. Oracle sqlldr数据加载

    1 sqlldr 传统路径:sqlldr会利用sql插入为我们加载数据 直接路径加载:sqlldr不适用sql,直接格式化数据块,绕开undo,避开redo,最快的方法就是并行直接路径加载 sqlld ...

  4. [Android]异步任务AsyncTask使用解析

    AsyncTask主要用来更新UI线程,比较耗时的操作可以在AsyncTask中使用. AsyncTask是个抽象类,使用时需要继承这个类,然后调用execute()方法.注意继承时需要设定三个泛型P ...

  5. JS四级复选框选中层次关系

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Pandas:表计算与数据分析

    目录 Pandas之Series Pandas之DataFrame 一.pandas简单介绍 1.pandas是一个强大的Python数据分析的工具包.2.pandas是基于NumPy构建的. 3.p ...

  7. Java面向对象-方法的定义及简单使用

    Java面向对象之方法 方法是对象的一部分,也称为行为: 先来一个简单实例: package com.java1234.chap03.sec03; public class Person { void ...

  8. Java面向对象-类与对象

    Java面向对象-类与对象 类与对象的关系 我们通俗的举个例子,比如人类是一种类,张三这个人就是人类的具体的一个个体,也就是java中的对象:这就是一个类与对象的关系: 类的定义 下面看实例 类的创建 ...

  9. python学习——练习题(1)

    """ 题目:有四个数字:1.2.3.4,能组成多少个互不相同且无重复数字的三位数?各是多少? """ import itertools d ...

  10. Docker镜像加速 | Docker 中国源 | 仓库

    镜像加速 | Docker 中国https://www.docker-cn.com/registry-mirror