Autor Beitrag
cherry
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 136

WinXP - Professional
RAD Studio 2009
BeitragVerfasst: Di 11.04.06 08:49 
Tach erstma..

Ich bin grad dran mir eine eigene Visuelle Komponente zu erschaffen.
Es soll einen Button geben...

Na jedenfalls wollte ich TColorPropery zum einstellen der Farben einbinden und das ist irgendwie nicht ganz ohne...
Ich muss die Komponente enzwei teilen, damit ich die Komponente später verwenden kann. Ist irgendwie neu,
damit man TColorProperty nicht während der Laufzeit verwenden darf (Typisch Windows).

Hier mein abgehalfterter Code: (Was mach ich falsch?)


Datei: EButton.pas

ausblenden volle Höhe Delphi-Quelltext
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:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
unit EButton;

interface

uses
  SysUtils, Classes, Controls, StdCtrls, Graphics;

type
  TEButton = class(TCustomControl)
  private
    FFont : TFont;
    { Private-Deklarationen }
  protected
    procedure Paint; override;
    { Protected-Deklarationen }
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Public-Deklarationen }
  published
    property Font: TFont read FFont write FFont;
    { Published-Deklarationen }
    
  end;

procedure Register;

implementation

procedure Register; //Procedure wird bei der Komponenteninstallation verwendet!
begin
  RegisterComponents('RComponents', [TEButton]);
end;

{------------------------------------------------}
{                                                }
{                                                }
{                  TEButton                      }
{                                                }
{------------------------------------------------}

constructor TEButton.Create(AOwner: TComponent);
begin
 inherited Create(AOwner);
 FFont:=TFont.Create;
end;

destructor TEButton.Destroy;
begin
 FFont.Free;
 inherited Destroy;
end;

procedure TEButton.Paint;
begin
 inherited;//Zeichen Procedure des Vorfahren aufrufen.
 if csDesigning in ComponentState then //Wenn sich die Komponente in Entwicklung befindet.
 begin
  {Zeichung eines Rahmens}
   Canvas.Brush.Style := bsSolid;
   Canvas.Brush.Color := clblue;
   Canvas.Pen.Color := clblack;
   Canvas.Rectangle(0,0,width,height);//Rechteck zeichnen

   {Namen der Komponente in die Mitte schreiben}
   canvas.Font := FFont;
   canvas.TextOut((width - Canvas.TextWidth(Name)) div 2,(height - Canvas.TextHeight(Name)) div 2,name);

   {Keine weitern Zeichnungen mehr ausführen}
   exit;//Verlässt die Procedure
 end;

 {Zeichung eines Rahmens}
 Canvas.Brush.Style := bsSolid;
 Canvas.Brush.Color := clblue;
 Canvas.Pen.Color := clblack;
 Canvas.Rectangle(0,0,width,height);//Rechteck zeichnen

 {Namen der Komponente in die Mitte schreiben}
 canvas.Font := FFont;
 canvas.TextOut((width - Canvas.TextWidth(Name)) div 2,(height - Canvas.TextHeight(Name)) div 2,name);

 {Keine weitern Zeichnungen mehr ausführen}
 exit;//Verlässt die Procedure
end;
end.


Datei: EButton_API.pas

ausblenden volle Höhe Delphi-Quelltext
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:
unit EButton_API;

interface

uses
   SysUtils,Classes,Controls,QGraphics,
   {$ifdef ver150} DesignIntf, DesignEditors,{$else} DsgnIntf,{$endif}EButton;

type
  TEColor = class(TColorProperty)
  public
   procedure Edit; override;
  // function  GetColor : TPropertyColor; override;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('RComponents', [TEButton]);
  RegisterPropertyEditor(TypeInfo(TColor), TEButton, 'Color', TRColor);
end;

{ TRColor }

procedure TColorProperty.Edit;
var
 ColorDialog: TColorDialog;
begin
    ColorDialog := TColorDialog.Create(Application);                { Editor erzeugen}
  try
        ColorDialog.Color := GetOrdValue;                           { Vorhandenen Wert verwenden }
        if ColorDialog.Execute then                          { Wenn der Anwender auf OK klickt ... }
            SetOrdValue(ColorDialog.Color);                   { ...das Ergebnis verwenden, um den Wert zu setzen}

  finally
        ColorDialog.Free;                                               { Editor freigeben }
   end;
 end;

end.


Danke für die Mühe...

Gruss Cherry

_________________
AM I TOO SEXY?
Ist das nur mein Gefühl, oder ist die ganze Welt verrückt geworden!?
cherry Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 136

WinXP - Professional
RAD Studio 2009
BeitragVerfasst: Do 13.04.06 07:09 
Bitte überhäuft mich nicht mit euren hilfreichen Antworten! :eyes:

Ich hab das selbe Problem in einem anderen Forum gepostet
und wir sind zu einer Lösung gekommen.

www.delphipraxis.net...enschaftseditor.html

Bye

_________________
AM I TOO SEXY?
Ist das nur mein Gefühl, oder ist die ganze Welt verrückt geworden!?