There's a bug in TIcon.ReleaseHandle. It reads...
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10:
| function TIcon.ReleaseHandle: HICON; begin with FImage do begin if FRefCount > 1 then NewImage(CopyIcon(FHandle), nil); Result := FHandle; FHandle := 0; end; Changed(Self); end; |
It should read...
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
| function TIcon.ReleaseHandle: HICON; begin with FImage do if FRefCount > 1 then NewImage(CopyIcon(FHandle), nil);
with FImage do begin Result := FHandle; FHandle := 0 end; Changed(Self); end; |
You get the problem when you have two TIcons that share the same
TIconImage. Suppose you want to change one of the icon's handles, you
say:
Delphi-Quelltext
1: 2: 3:
| oldIcon := icon1.ReleaseHandle; if oldIcon <> 0 then DestroyIcon (oldIcon); icon1.Handle := newIcon; |
.. but if you use the (buggy) version of ReleaseHandle on Icon1, it,
1. Creates a separate image for icon1 with a ref count of 1, and
decrements the ref count for the original image (which is still used by
icons2). (so far so good)
2. It returns the handle of the *original image* and sets the handle
to 0. The original image is still used by icon2, which goes mad.
The 'fixed version'..
1. Creates a separate image for icon1 with a ref count of 1, and
decrements the ref count for the original image (which is still used by
icons2). (so far so good)
2. It returns the handle of the *new* and sets it's handle to 0. The
original image is still used by icon2, which continues to work ok.
von
homepages.borland.co...seNet/1999/0114b.txt