[英]Populating a ListView at run-time
I'm trying to populating a ListView at run-time with DynamicAppearance.我正在尝试在运行时使用 DynamicAppearance 填充 ListView。 The text parts work well, but the image is always the same as the last one.
文本部分运行良好,但图像始终与最后一个相同。 This code adds to all items the same image.
此代码向所有项目添加相同的图像。 I want to add a image to just one item.
我只想为一个项目添加图像。
procedure TfrmMain.crialista;
var
Aux1 : TStringDynArray; // Usado para trocar o nome.exe por nome_Icon
icone : string; // Recebe o caminho completo para pegar o icone
Programa : Tprograma; // Contem todas as informações do programa , é passado para cada item da listbox.
Path : string; //acho que não serve de nada
// tb não usa pra nada
Aux : integer;
ARPrograma : array of TPrograma ;
searchaux: string;
Contador : integer;
begin
listview1.Items.clear;
TThread.CreateAnonymousThread(procedure
begin
QryEIS.Close;
QryEIS.open;
Contador:= 0 ;
SetLength(ARPrograma, QRyEIS.RecordCount );
QryEIS.First;
while not QryEIS.Eof do
begin
QryDiretorio.Close;
QryDiretorio.ParamByName('NomeDoSistema').Value:= QryEIS.FieldByName('DescricaoEIS').Value;
QryDiretorio.Open;
// Pegando o Icone do programa...
if QryDiretorio.RecordCount = 0 then //escrever o erro aqui
else
begin
aux1 := splitString( QryDiretorio.FieldByName('Sistema').Value, '.') ;
icone := 'F:\Sistemas\Icones\Launcher\' +aux1[0]+'_Icon.ico';
// ImageList1.AddMasked(Bmp,clFuchsia);
imagecontrol1.LoadFromFile(icone);
ARPrograma[Contador].Icone := imagecontrol1.bitmap;
ARPrograma[Contador].Nome:= QryDiretorio.FieldByName('NomeDoSistema').Value;
ARPrograma[Contador].NomeExe := QryDiretorio.FieldByName('Sistema').Value;
ARPrograma[Contador].SingleUser := QryDiretorio.FieldByName('SingleUser').Value ;
// Caminho da unidade C (PathC) e da unidade F (Path)
if QryDiretorio.FieldByName('SingleUser').Value = 'T' then
begin
ARPrograma[Contador].path := trim(QryDiretorio.FieldByName('Origem').Value)+'\'+trim(QryDiretorio.FieldByName('Sistema').Value);
ARPrograma[Contador].pathC := trim(QryDiretorio.FieldByName('destino').Value)+'\'+qryNome.FieldByname('NomeUsuario').Value+'\'+trim(QryDiretorio.FieldByName('Sistema').Value);
ARPrograma[Contador].DiretorioUser := trim(QryDiretorio.FieldByName('destino').Value)+'\'+qryNome.FieldByname('NomeUsuario').Value;
ARPrograma[Contador].Diretorio :=trim(QryDiretorio.FieldByName('destino').Value);
ARPrograma[Contador].SingleUser := QryDiretorio.FieldByName('SingleUser').Value ;
end
else
begin
ARPrograma[Contador].path := trim(QryDiretorio.FieldByName('Origem').Value)+'\'+trim(QryDiretorio.FieldByName('Sistema').Value);
ARPrograma[Contador].pathC := trim(QryDiretorio.FieldByName('destino').Value)+'\'+trim(QryDiretorio.FieldByName('Sistema').Value);
ARPrograma[Contador].Diretorio := trim(QryDiretorio.FieldByName('destino').Value);
end ;
aux := fileage(ARPrograma[Contador].path);
ARPrograma[Contador].DataMod := FileDateToDateTime(aux);
ARPrograma[Contador].Versao := Sto_GetFmtFileVersion(Programa.path , '');
if Programa.Versao <> '' then
begin
aux1 := splitString (Programa.Versao , '.');
ARPrograma[Contador].iVer[1] := strtoint(aux1[0]);
ARPrograma[Contador].iVer[2] := strtoint(aux1[1]);
ARPrograma[Contador].iVer[3] := strtoint(aux1[2]);
ARPrograma[Contador].iVer[4] := strtoint(aux1[3]);
end;
if fileExists(programa.pathC) then
begin
ARPrograma[Contador].VersaoC := Sto_GetFmtFileVersion(Programa.pathC , '');
if Programa.VersaoC <> '' then // Mesma coisa do comentario do F:
begin
aux1 := splitString (Programa.VersaoC , '.');
ARPrograma[Contador].iVerC[1] := strtoint(aux1[0]);
ARPrograma[Contador].iVerC[2] := strtoint(aux1[1]);
ARPrograma[Contador].iVerC[3] := strtoint(aux1[2]);
ARPrograma[Contador].iVerC[4] := strtoint(aux1[3]);
end;
end ;
// Here i call the CriaFrama.
criaframa(ARPrograma[Contador], Contador);
contador := Contador +1;
end;
QryEIS.Next;
end;
TThread.Synchronize(nil, procedure
begin
// some visual thing....
end);
end).Start;
end;
procedure TfrmMain.CriaFrama(s: Tprograma; a : integer);
var
anitem : TListViewItem;
txt : TListItemText;
img : TListItemImage;
begin
with FrmMain do
begin
anitem := Listview1.Items.Add;
with anitem do
begin
txt := TListItemText(Objects.FindDrawable('Text1'));
txt.Text := S.Nome;
//the image part
img := TListItemImage(Objects.FindDrawable('Image2'));
img.Bitmap := s.Icone;
end;
end;
Just for i can post the item...................只是因为我可以发布该项目......................
It looks like your post is mostly code;看起来您的帖子主要是代码; please add some more details.
请添加更多详细信息。 It looks like your post is mostly code;
看起来您的帖子主要是代码; please add some more details.
请添加更多详细信息。 It looks like your post is mostly code;
看起来您的帖子主要是代码; please add some more details.
请添加更多详细信息。
First of all, thank so much for helping me, Remy Lebeau.首先,非常感谢帮助我,Remy Lebeau。 As he said in the comments, the problem was in pointing all items to the same bitmap and not synchronizing the segment when changing something in the user interface.
正如他在评论中所说,问题在于将所有项目指向同一个位图,并且在更改用户界面中的某些内容时不同步该段。 (Not sync generates some access violation errors) The code:
(不同步会产生一些访问冲突错误)代码:
procedure TfrmMain.crialista;
var
Aux1 : TStringDynArray;
icone : string;
Path : string;
Aux : integer;
ARPrograma : array of TPrograma ;
searchaux: string;
Contador : integer;
bitmap : FMX.Graphics.TBitmap;
begin
listview1.Visible := false;
load_menu.Visible := true;
Load_menu.Enabled := true;
frmMain.LPrincipal.RemoveObject(0);
listview1.Items.clear;
searchaux:= searchBox1.Text;
searchBox1.Text.Empty;
TThread.CreateAnonymousThread(procedure
var bitmap : FMX.Graphics.TBitmap;
begin
QryEIS.Close;
QryEIS.open;
Contador:= 0 ;
SetLength(ARPrograma, QRyEIS.RecordCount );
QryEIS.First;
while not QryEIS.Eof do
begin
QryDiretorio.Close;
QryDiretorio.ParamByName('NomeDoSistema').Value :=
QryEIS.FieldByName('DescricaoEIS').Value;
QryDiretorio.Open;
if QryDiretorio.RecordCount = 0 then
else
begin
TThread.Synchronize(nil, procedure
begin
aux1 :=splitString( QryDiretorio.FieldByName('Sistema').Value, '.') ;
icone := 'F:\Sistemas\Icones\Launcher\' +aux1[0]+'_Icon.ico';
BitMap := FMX.Graphics.TBitmap.CreateFromFile(icone);
ARPrograma[Contador].Icone := bitmap ;
end);
ARPrograma[Contador].Nome:= QryDiretorio.FieldByName('NomeDoSistema').Value;
ARPrograma[Contador].NomeExe := QryDiretorio.FieldByName('Sistema').Value;
ARPrograma[Contador].SingleUser := QryDiretorio.FieldByName('SingleUser').Value ;
if QryDiretorio.FieldByName('SingleUser').Value = 'T' then
begin
ARPrograma[Contador].path := trim(QryDiretorio.FieldByName('Origem').Value)+'\'+trim(QryDiretorio.FieldByName('Sistema').Value);
ARPrograma[Contador].pathC := trim(QryDiretorio.FieldByName('destino').Value)+'\'+qryNome.FieldByname('NomeUsuario').Value+'\'+trim(QryDiretorio.FieldByName('Sistema').Value);
ARPrograma[Contador].DiretorioUser := trim(QryDiretorio.FieldByName('destino').Value)+'\'+qryNome.FieldByname('NomeUsuario').Value;
ARPrograma[Contador].Diretorio :=trim(QryDiretorio.FieldByName('destino').Value);
ARPrograma[Contador].SingleUser := QryDiretorio.FieldByName('SingleUser').Value ;
end
else
begin
ARPrograma[Contador].path := trim(QryDiretorio.FieldByName('Origem').Value)+'\'+trim(QryDiretorio.FieldByName('Sistema').Value);
ARPrograma[Contador].pathC := trim(QryDiretorio.FieldByName('destino').Value)+'\'+trim(QryDiretorio.FieldByName('Sistema').Value);
ARPrograma[Contador].Diretorio := trim(QryDiretorio.FieldByName('destino').Value);
end ;
//Pega a versão do .exe da unidade F:
aux := fileage(ARPrograma[Contador].path); // Do not use that , use the 2 params FileAge, for more information check the comments
ARPrograma[Contador].DataMod := FileDateToDateTime(aux);
ARPrograma[Contador].Versao := Sto_GetFmtFileVersion(Programa.path , '');
if Programa.Versao <> '' then //caso não seja nulo , coloca no array de integer , para ficar mais facil de comparar na hora de atualizar. (fica em Udetalhes)
begin
aux1 := splitString (Programa.Versao , '.');
ARPrograma[Contador].iVer[1] := strtoint(aux1[0]);
ARPrograma[Contador].iVer[2] := strtoint(aux1[1]);
ARPrograma[Contador].iVer[3] := strtoint(aux1[2]);
ARPrograma[Contador].iVer[4] := strtoint(aux1[3]);
end;
if fileExists(programa.pathC) then
begin
ARPrograma[Contador].VersaoC := Sto_GetFmtFileVersion(Programa.pathC , '');
if Programa.VersaoC <> '' then
begin
aux1 := splitString (Programa.VersaoC , '.');
ARPrograma[Contador].iVerC[1] := strtoint(aux1[0]);
ARPrograma[Contador].iVerC[2] := strtoint(aux1[1]);
ARPrograma[Contador].iVerC[3] := strtoint(aux1[2]);
ARPrograma[Contador].iVerC[4] := strtoint(aux1[3]);
end;
end ;
TThread.Synchronize(nil, procedure
begin
criaframa(ARPrograma[Contador], Contador);
end);
contador := Contador +1;
end;
QryEIS.Next;
end;
TThread.Synchronize(nil, procedure
begin
listview1.Visible := true;
load_menu.Visible := false;
Load_menu.Enabled := false;
searchBox1.Text :='';
end);
end).Start;
end;
The other part still the same.其他部分还是一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.