Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Problem mit TBitmap property (https://www.delphipraxis.net/91220-problem-mit-tbitmap-property.html)

.chicken 1. Mai 2007 18:17


Problem mit TBitmap property
 
Also ich versuche gerade mir eine Button Komponente zu programmieren.
Dabei habe ich bisher folgenden Ansatz!
Delphi-Quellcode:
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.
Mein Problem: Ich muss immer bevor ich der Bild property ein Bitmap zuweisen will, noch ein Bild := TBitmap.Create aufrufen!
Hatte das auch schonmal im Constructor von TGraphicButton stehen, aber das hat trotzdem nicht funktioniert!
Was muss ich ändern?

Keldorn 1. Mai 2007 18:57

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

.chicken 1. Mai 2007 18:59

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!

SirThornberry 1. Mai 2007 19:02

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.

mkinzler 1. Mai 2007 19:04

Re: Problem mit TBitmap property
 
Das Speicherleck. welches du damit bastelst, betrifft dann ja alle Programme, welche die Komponente verwenden.

.chicken 1. Mai 2007 19:20

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