Note that there are some explanatory texts on larger screens.

plurals
  1. POThreaded loading of icons in Delphi
    primarykey
    data
    text
    <p>Using Delphi 2009, trying to make a launcher. In order to make it "snappy" I would really like to load icons in a background thread.</p> <p>I have used the solution found here : <a href="https://stackoverflow.com/questions/1703186/can-48x48-or-64x64-icons-be-obtained-from-the-vista-shell">Can 48x48 or 64x64 icons be obtained from the Vista Shell?</a></p> <p>This works fine, if NOT run in a thread. As soon as I put it in a thread, some icons are not "fetched", or being some kind of generic icon. I even tried serializing the threads (making them obsolote, in effect) but it yields the same results.</p> <p>So, the question is: How do I load icons (with the same available options as the linked example) in a thread?</p> <p>/Lars</p> <p>Edit: Added some very basic error-checking in GetIconFromFile</p> <pre><code>if SHGetFileInfo( PChar( aFile ), FILE_ATTRIBUTE_NORMAL, SFI, SizeOf( TSHFileInfo ), SHGFI_ICON or SHGFI_LARGEICON or SHGFI_SHELLICONSIZE or SHGFI_SYSICONINDEX or SHGFI_TYPENAME or SHGFI_DISPLAYNAME ) &lt;&gt; 0 then begin if not Assigned( aIcon ) then aIcon := TIcon.Create; aImgList := GetImageListSH( SHIL_FLAG ); aIndex := SFI.iIcon; if aImgList &lt;&gt; 0 then aIcon.Handle := ImageList_GetIcon( aImgList, aIndex, ILD_NORMAL ); end; </code></pre> <p>This doesn't make any diffenrence. I am still getting some generic icons (only when this is called in a thread, though)</p> <p>Edit2 : Threading-code (very simple) :</p> <pre><code>procedure TIconLoader.Execute; var Item : TGridItem; I : TIcon; begin inherited; while not terminated do begin Item := nil; if assigned(FOnNeedGridItem) then begin Synchronize( procedure begin FOnNeedGridItem(Self, Item); end ); end; if assigned(Item) then begin GetIconFromFile(Item.FFilename, I, SHIL_EXTRALARGE); Synchronize( procedure begin Item.SetIcon(I); end ); // I.Free; end else Terminate; end; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload