![]() |
Problem mit TBitmap property
Also ich versuche gerade mir eine Button Komponente zu programmieren.
Dabei habe ich bisher folgenden Ansatz!
Delphi-Quellcode:
Mein Problem: Ich muss immer bevor ich der Bild property ein Bitmap zuweisen will, noch ein Bild := TBitmap.Create aufrufen!
unit GraphicButton;
interface uses SysUtils, Classes, Controls, Graphics; type TGraphicButton = class(TGraphicControl) private FBild: TBitmap; FBildClick: TBitmap; procedure SetBild(Value: TBitmap); procedure SetBildClick(Value: TBitmap); protected procedure Paint; Override; procedure Click; public property Canvas; constructor Create(AOwner: TComponent); published property Caption; property Color; property Bild: TBitmap read FBild write SetBild; property BildClick: TBitmap read FBildClick write SetBildClick; property Font; end; procedure Register; implementation procedure Register; begin RegisterComponents('Eigene', [TGraphicButton]); end; constructor TGraphicButton.Create(AOwner: TComponent); begin inherited Create(AOwner); FBild := TBitmap.Create; FBildClick := TBitmap.Create; end; procedure TGraphicButton.Paint; begin inherited; if Font <> nil then Canvas.Font := Font; if csDesigning in ComponentState then begin Canvas.Brush.Style := bsClear; Canvas.Pen.Style := psDashDot; Canvas.Rectangle(0, 0, width, height); Canvas.TextOut((width - Canvas.TextWidth(Caption)) div 2,(height - Canvas.TextHeight(Caption)) div 2, Caption); end else begin Canvas.Brush.Style := bsSolid; Canvas.Pen.Style := psSolid; Canvas.Brush.Color := Color; Canvas.Rectangle(0, 0, width, height); if Assigned(FBild) then Canvas.Draw(0, 0, FBild); Canvas.Brush.Style := bsClear; Canvas.TextOut((width - Canvas.TextWidth(Caption)) div 2,(height - Canvas.TextHeight(Caption)) div 2, Caption); end; end; procedure TGraphicButton.Click; begin end; procedure TGraphicButton.SetBild(Value: TBitmap); begin FBild.Assign(Value); Repaint; end; procedure TGraphicButton.SetBildClick(Value: TBitmap); begin FBildClick.Assign(Value); Repaint; end; end. Hatte das auch schonmal im Constructor von TGraphicButton stehen, aber das hat trotzdem nicht funktioniert! Was muss ich ändern? |
Re: Problem mit TBitmap property
Hallo
dein eigener Constructor wird gar nicht aufgerufen, da fehlt das override. und die Bilder solltest du auch wieder freigeben. Mfg Frank |
Re: Problem mit TBitmap property
Ahsoooo, danke ^^
Das mit dem Freigeben is klar aber soweit es noich garnet funktioniert is das ja erstma Nebensache ^^ Ok danke soweit! |
Re: Problem mit TBitmap property
nebensache? man sollte sich von Anfang an daran gewöhnen dinge auch wieder frei zu geben. Ansonsten passiert es schnell das man es dann vergisst.
|
Re: Problem mit TBitmap property
Das Speicherleck. welches du damit bastelst, betrifft dann ja alle Programme, welche die Komponente verwenden.
|
Re: Problem mit TBitmap property
Jo, habter Recht ;-)
Werde drauf achten, danke :) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:08 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz