Bonjour

j ai 2 questions

1 - Pourquoi ma méthode pour remplir un TlistView, avec des images est lente, comment l 'optimiser
2 - vu la lenteur, j ai voulu mettre cette methode dans un thread, il y rentre bien dedans, mais rien ne s affiche. POurquoi et comment faire ??

merci

voici mon code


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
constructor TThreadJob.Create(CreateSuspended: Boolean);
begin
  inherited Create(CreateSuspended);
 
  FreeOnTerminate := true;
  Priority := tpNormal; //  TThreadPriority = (tpIdle, tpLowest, tpLower, tpNormal, tpHigher, tpHighest, tpTimeCritical);
end;
 
procedure TThreadJob.Execute;
var
  i, iIncrement, iCountImages: integer;
  bmp: TBitmap;
  bmpjpg: TBitmap;
  jpg: TJpegImage;
  sNomImage: string;
  tQuery: TIBQuery;
  bOk: Boolean;
  tampon: TMemoryStream;
begin
  with FBiblioMultimedia do
    begin
     ListView1.DisableAlign;
      btnDel.Enabled := False;
 
      Label1.Caption := '';
      ImageList1.Clear;
 
      ImageList1.Height := I_TAILLE;
      ImageList1.Width := I_TAILLE;
 
      ListView1.Items.Clear;
      ListView1.Clear;
      iIncrement := 0;
 
      tQuery := TIBQuery.Create(FBiblioMultimedia);
      tQuery.Database := dm.ibd_BASE;
      tQuery.Transaction := dm.IBT_BASE;
      tQuery.Close;
      tQuery.SQL.Clear;
      tQuery.SQL.Add(lsSQL);
 
      tQuery.DisableControls;
      tQuery.Params[0].AsInteger := dm.NumDossier;
      tQuery.Open;
      tQuery.Last;
      tQuery.First;
 
      iCountImages := tQuery.RecordCount;
 
      if iCountImages <= 0 then
        begin
          tQuery.close;
          tQuery.EnableControls;
          tQuery.Free;
          exit;
        end;
 
      SetLength(tNameImage, iCountImages);
      SetLength(tClefImage, iCountImages);
 
      while not tQuery.Eof do
        begin
          bOk := False;
 
          sNomImage := tQuery.FieldByName('MULTI_PATH').asstring;
          tNameImage[iIncrement] := sNomImage;
          tClefImage[iIncrement] := tQuery.FieldByName('MULTI_CLEF').AsInteger;
 
          Inc(iIncrement);
 
          jpg := TJpegImage.Create;
          bmp := TBitmap.Create;
          bmpjpg := TBitmap.Create;
 
          Tampon := TMemoryStream.Create;
          TBlobField(tQuery.FieldByName('MULTI_REDUITE')).SaveToStream(tampon);
          tampon.Seek(0, soFromBeginning);
          jpg.LoadFromStream(tampon);
 
          tampon.Destroy;
 
          if (jpg.Width > I_TAILLE) or (jpg.Height > I_TAILLE) then
            if (jpg.Width > 500) or (jpg.Height > 400) then
              jpg.Scale := jsEighth;
 
          if tQuery.FieldByName('MULTI_IMAGE_RTF').AsInteger < 1 then
            begin
              if (jpg.Width > I_TAILLE) or (jpg.Height > I_TAILLE) then
                ResizeJpg2bmp(jpg, bmp, I_TAILLE)
            end
          else
            ResizeJpg2bmp(jpg, bmp, 36);
 
          CentreDansBmpCtr(bmp);
          ImageList1.Add(bmp, nil);
 
          bmp.Free;
          jpg.Free;
          bmpjpg.Free;
 
          tQuery.next;
        end;
 
      tQuery.Close;
      tQuery.EnableControls;
      tQuery.Free;
 
      btnSelection.Enabled := iIncrement > 0;
 
      if iIncrement > 0 then
        begin
          with ListView1 do
            begin
              with Columns.Add do
                begin
                  Caption := 'Image';
                  Autosize := True;
                  Alignment := taLeftJustify;
                end;
              with Columns.Add do
                begin
                  Caption := 'Nom';
                  Autosize := True;
                  Width := 500;
                end;
 
              for i := 0 to iIncrement - 1 do
                begin
                  with Items.Add do
                    begin
                      Caption := ExtractFileName(tNameImage[i]);
                      SubItems.Add(tNameImage[i]);
                      ImageIndex := i; // numéro de l'image dans ImageList1
                    end;
                end;
            end;
 
          ListView1.ItemIndex := 0;
        end;
 
      btnDel.Enabled := ListView1.Items.Count > 0;
      ListView1.EnableAlign;
 
     //showmessage('oui');
      if ListView1.Items.Count > 0 then
        begin
          ibMajMultimedia.Close;
          ibMajMultimedia.Params[0].AsInteger := dm.NumDossier;
          ibMajMultimedia.Open;
 
          ListView1.Items[ListView1.Items.Count - 1].Selected := True;
          ListView1Click(Self);
        end;
 
    end;
 
  // -- On tue le thread -------------------
  Terminate;
end;