[ Passwd @ 28.12.2005. 19:46 ] @
Radim bezveze nov ukomponentu, i naslijedim TButton i kreiram Edit1 i Edit2, ali kad komponentu postavim na formu, ti editi se uopce ne vide..

Code:

unit TMojDigitron;

interface

uses
  SysUtils, Classes, Controls, StdCtrls, Dialogs;

type
  TDigitron = class(TButton)
  private
    { Private declarations }
    Edit1:TEdit;
    Edit2:TEdit;
    procedure zbroji(Sender: TObject);
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner:TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property Align;
    property Anchors;
    property AutoSize;
    property BiDiMode;
    property Color nodefault;
    property Constraints;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Font;
    property ParentBiDiMode;
    property ParentColor;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property Visible;
    property WordWrap;
    property OnClick;
    property OnContextPopup;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDock;
    property OnStartDrag;
  end;

procedure Register;

implementation


procedure TDigitron.zbroji(Sender: TObject);
begin
ShowMessage(IntToStr(StrToInt(Edit1.Text)+StrToInt(Edit2.Text)));
end;


constructor TDigitron.Create(AOwner:TComponent);
begin
 inherited Create(AOwner);
 Edit1:=TEdit.Create(self);
 Edit2:=TEdit.Create(self);

 Edit1.Visible:=true;
 Edit1.Top:=5;
 Edit1.Left:=10;

 Edit2.Visible:=true;
 Edit2.Top:=10;
 Edit2.Left:=10;

 Caption:='Zbroji';
 OnClick:=zbroji;
end;


destructor TDigitron.Destroy;
begin
Edit1.Free;
Edit2.Free;

inherited;
end;

procedure Register;
begin
  RegisterComponents('Samples', [TDigitron]);
end;

end.




Prije ovoga sam stavio umjesto Self Parent..nije ni tako htjelo radit!

Unaprijed hvala,p0z.
[ Milos D @ 28.12.2005. 20:01 ] @
Edit1.parent := self;
Edit2.parent := self;
[ Relaja @ 28.12.2005. 20:25 ] @
Code:
constructor TDigitron.Create(AOwner:TComponent);
begin
 inherited Create(AOwner);
 Edit1:=TEdit.Create(self);
 Edit2:=TEdit.Create(self);


Ja mislim da je greska ovde .Umesto self treba da stavis isto AOwner.
Poz.
[ Passwd @ 28.12.2005. 20:55 ] @
Ne znam nikako nece, samo se stvar jos pogorsala
Aj probajte vi..napravite paket od ovog koda i dodajte tu komponentu, i stavite ju na formu i recite dal vam se srusi delphi...meni vec stalno za redom cim stavim tu komponentu delphi padne..


Code:

unit TMojDigitron1;

interface

uses
  SysUtils, Classes, Controls, StdCtrls, Dialogs;

type
  TMojDigitron = class(TButton)
  private
    { Private declarations }
    Edit1:TEdit;
    Edit2:TEdit;
    procedure zbroji(Sender: TObject);
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner:TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
  end;

procedure Register;

implementation


procedure TMojDigitron.zbroji(Sender: TObject);
begin
ShowMessage(IntToStr(StrToInt(Edit1.Text)+StrToInt(Edit2.Text)));
end;


constructor TMojDigitron.Create(AOwner:TComponent);
begin
inherited Create(self);
Edit1:=TEdit.Create(Parent);
Edit2:=TEdit.Create(Parent);
Edit1.Parent:=self;
Edit2.Parent:=self;

 Edit1.Visible:=true;
 Edit1.Top:=5;
 Edit1.Left:=10;

 Edit2.Visible:=true;
 Edit2.Top:=35;
 Edit2.Left:=10;

 Top:=65;
 Left:=10;
 Caption:='Zbroji';
 OnClick:=zbroji;


end;



destructor TMojDigitron.Destroy;
begin
Edit1.Free;
Edit2.Free;

inherited;
end;

procedure Register;
begin
  RegisterComponents('Samples', [TMojDigitron]);
end;

end.

[ Srki_82 @ 28.12.2005. 21:14 ] @
Delphi ti se rusi zbog:
Code:
inherited Create(self);
[ Milos D @ 28.12.2005. 21:42 ] @
Owner je vlasnik komponente. To znaci da kada se unistava Owner automatski se unistavaju i sve njegove komponente. Zato Edit treba da kreiras tako da owner bude self (tj. tvoja komponenta).

Parent je vizuelna kontrola (dakle ne moze biti bilo koja komponenta) na kojoj se nalazi tj. "iscrtava" kontrola. U konstruktoru, self.Parent je NIL. Ali self nije nil pa zato...

inherited Create(AOwner);
Edit1:=TEdit.Create(self);
Edit2:=TEdit.Create(self);
Edit1.Parent:=self;
Edit2.Parent:=self;

i u destruktoru ne moras da unistavas edite.

[ Passwd @ 28.12.2005. 22:11 ] @
Da u tome je bio problem..
Problem rjesen, hvala svima!