Hallo,
In meinem Programm verwende ich für verschiedene Buttons folgende Funktion...
(Quelle: swissdelphicenter.ch)
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:
| procedure AddDisableBMP(SB : array of TObject); var BM, SBM : TBitmap; w, x, y, NewColor, i : integer; PixelColor : TColor; begin BM := TBitmap.Create; SBM := TBitmap.Create; try for i := 0 to High(SB) do begin if (SB[i] is TSpeedButton) then BM.Assign((SB[i] as TSpeedButton).Glyph) else if (SB[i] is TBitBtn) then BM.Assign((SB[i] as TBitBtn).Glyph) else begin Exit; end;
if not Assigned(BM) or (BM.Width <> BM.Height) then begin Exit; end;
w := BM.Width; SBM.Width := w * 2; SBM.Height := w; SBM.Canvas.Draw(0, 0, BM);
for x := 0 to w - 1 do for y := 0 to w - 1 do begin PixelColor := ColorToRGB(BM.Canvas.Pixels[x, y]); NewColor := Round((((PixelColor shr 16) + ((PixelColor shr 8) and $00FF) + (PixelColor and $0000FF)) div 3)) div 2 + 96; BM.Canvas.Pixels[x, y] := RGB(NewColor, NewColor, NewColor); end;
SBM.Canvas.Draw(w, 0, BM);
if (SB[i] is TSpeedButton) then with (SB[i] as TSpeedButton) do begin Glyph.Assign(SBM); NumGlyphs := 2; end else with (SB[i] as TBitBtn) do begin Glyph.Assign(SBM); NumGlyphs := 2; end; BM := TBitmap.Create; SBM := TBitmap.Create; end; finally BM.Free; SBM.Free; end; end; |
Die Glyphs der Buttons werden dann um den grauen Bereich erweitert, der bei deaktivierten Buttons anzeigt wird. Nun das Problem: Diese Procedure gibt irgendwelche GDI-Objekte nicht wieder richtig frei (Siehe Thread
www.delphi-forum.de/viewtopic.php?t=30444). Dadurch kommt es bei längerer Anwendungslaufzeit zur beschriebenen EOutOfResources Exception. Was macht die Routine falsch bzw. wie kann ich die grauen Bitmaps anders erzeugen, so dass beim deaktivieren des Buttons nicht das Glyph verschwindet sondern ein graues erscheint.
Vielen Dank im Voraus...