Autor Beitrag
Diach
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: So 27.10.02 15:45 
Hi!

Ich hätte da mal die Frage, wie ich eine Neue Komponente erstellen kann.
Sie soll z.B. ein Panel sein, dass aber von Anfang an, eine bestimmte Grösse, Farbe und Caption hat, damit ich das nicht jedesmal neu machen muss.
Wie genau mach ich das, dass das auch funzt?

Schonmal Danke :P
Diach
aogwaba
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109



BeitragVerfasst: So 27.10.02 16:14 
Hi!

leite eine neue Klasse von TLabel ab:

ausblenden Quelltext
1:
2:
3:
type TmyLabel=class(TLabel)
  constructor create(AOwner: TComponent;x,y:integer;farbe:TColor;text:String);
end;


dann die Implementation des Konstructors:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
constructor TMyLabel.create(AOwner: TComponent;x,y:integer;farbe:TColor;text:String);
begin
inherited create( AOwner);
width:=x;
height:=y;
color:=farbe;
caption:=text;
end;


und so wird Instantziert:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Button1Click(Sender: TObject);
var mylabel:TMyLabel;
begin
myLabel:=TMyLabel.create(self,100,100,clGray ,'test');
myLabel.parent:=self;
end;


beim beenden des Programms myLabel.free nicht vergessen!

cu
waba
Diach Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: So 27.10.02 16:26 
Velen Dank schonmal!

KAnn ich das auch so lösen, dass meine Neue Komponente auch in der Komponentenpalette erscheint, damit ich meine neue Komponente auch in anderen Programmen verwenden kann?

Diach
aogwaba
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109



BeitragVerfasst: So 27.10.02 16:52 
Hi!

ja geht auch, is aber ein bissel mehr Arbeit:

www.tutorials.delphi-source.de/tswitch/

cu
waba
Diach Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: So 27.10.02 19:52 
Na ich werd mich da jetzt mal einlesen. :shock:

Vielen Dank nochmal!!!

Diach
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: So 27.10.02 20:48 
aogwaba hat folgendes geschrieben:
ja geht auch, is aber ein bissel mehr Arbeit:

Das ist wohl die kleinste Arbeit beim Entwickeln von Komponenten:
ausblenden Quelltext
1:
2:
3:
4:
procedure Register;
begin
  RegisterComponents ('Beispiele', [TMyLabel]);
end;


Gruß
TINO
aogwaba
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109



BeitragVerfasst: So 27.10.02 21:23 
so einfach geht das, wieder was gelernt ;)

cu
waba
Diach Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: So 27.10.02 21:34 
so einfach geht das doch nicht!

ich habe mir das tuturial jetzt durchgelesen und weiss jetzt wie ich meine neue komponente in die Kompopalette bekomme. aber ich weiss immernoch nicht so recht, wie ich es anstelle, dass z.B. mein "MyPanel" von anfag an grün ist! also ich möchte es in der kompopalette anklicken und es ab die form bringen und es sollte sofort schön grün sein. wird da leider auch nicht beschrieben.

Diach
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 28.10.02 00:23 
Diach hat folgendes geschrieben:
so einfach geht das doch nicht!

Meine Antwort bezog sich auf die Frage:
Diach hat folgendes geschrieben:
KAnn ich das auch so lösen, dass meine Neue Komponente auch in der Komponentenpalette erscheint

Und das ist mit dem von mir gepostenten Code beantwortet. Oder erscheint die Komponente nicht in der Komponentenpalette?

Damit Deine Komponenten von anfang an in grün dargestellt wird sollte dies hier helfen:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
type
  TMyLabel = class (tLabel)
    Public
      Constructor Create (AOwner: tComponent);
  End;

{...}

Constructor TMyLabel.Create (AOwner: tComponent);
Begin
  Inherited;
  Color := clRed;
End;


Gruß
TINO