Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Constructor on TObject descendant

Posted on 2004-04-01
9
Medium Priority
?
533 Views
Last Modified: 2013-11-23
The cReate for a TObject descendant is not getting fired, in fact it's not trecognised by the complier (no blue dots). here's some sample code. What have I done wrong?

Thanks, Tom.

  TOne = class(TObject)
  private
  protected
  public
  published
  end;


  TTwo = class(TOne)
  private
    Flbl : TLabel;
  protected
  public
    constructor create;
    destructor destroy; override;
  published
  end;

constructor TTwo .create;
begin
  inherited create;

  Flbl := TLabel.Create(nil);
end;

destructor TTwo .destroy;
begin
  Flbl.free;
  inherited;
end;
0
Comment
Question by:tomcorcoran
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 10730735
unit Unit_Q_20939766;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TOne = class(TObject)
    private
    protected
    public
    published
  end;

  TTwo = class(TOne)
    private
      Flbl : TLabel;
    protected
    public
      constructor create;
      destructor destroy; override;
    published
  end;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    private { Private declarations }
    public  { Public declarations }
  end;

var
  Form1: TForm1;
  Two:   TTwo;

implementation

{$R *.dfm}

constructor TTwo .create;
begin
  inherited create;

  Flbl := TLabel.Create(nil);
end;

destructor TTwo .destroy;
begin
  Flbl.free;
  inherited;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Two := TTwo.Create;
  Two.Flbl.Parent := Self;
  Two.Flbl.Caption := 'Hello everybody';
end;

end.

emil
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10730752
>in fact it's not trecognised by the complier (no blue dots).
In my test example it is recognised by compiler and works ?
I see the caption of Flbl on my form....

emil
0
 

Author Comment

by:tomcorcoran
ID: 10730821
Ok, not sure what I've missed here :-) Must be something else in my code I am missing.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TOne = class(TObject)
    private
    protected
    public
    published
  end;

  TTwo = class(TOne)
    private
      Flbl : TLabel;
    protected
    public
      constructor create;
      destructor destroy; override;
    published
  end;


  TThree = class(TTwo)
    private
      Flbl2 : TLabel;
    protected
    public
      constructor create;
      destructor destroy; override;
    published
  end;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    private { Private declarations }
    public  { Public declarations }
  end;

var
  Form1: TForm1;
  Two:   TTwo;
  Three:   TThree;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Two := TTwo.Create;
  Two.Flbl.Parent := Self;
  Two.Flbl.Caption := 'Hello everybody';

  Three := Three.Create;
  Three.Flbl.Parent := Self;
  Three.Flbl.Caption := 'Ya know it';
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Three.Free;
  Two.Free;
end;

{ TTwo }

constructor TTwo.create;
begin
  inherited create;

  Flbl := TLabel.Create(nil);
end;

destructor TTwo.destroy;
begin
  Flbl.free;
  inherited;
end;

{ TThree }

constructor TThree.create;
begin
  inherited create;

  Flbl2 := TLabel.Create(nil);
end;

destructor TThree.destroy;
begin
  Flbl2.free;
  inherited;
end;



end.

 I get no blue dots on the last destructor :

destructor TThree.destroy;
begin
  Flbl2.free;
  inherited;
end;
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Accepted Solution

by:
esoftbg earned 200 total points
ID: 10730875
here are blue dots:

unit Unit_Q_20939766;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls;

type
  TOne = class(TObject)
    private
    protected
    public
    published
  end;

  TTwo = class(TOne)
    private
      Flbl : TLabel;
    protected
    public
      constructor Create(AOwner: TWinControl); dynamic;
      destructor  Destroy; override;
    published
  end;

  TThree = class(TTwo)
    private
      Flbl2 : TLabel;
    protected
    public
      constructor Create(AOwner: TWinControl); override;
      destructor Destroy; override;
    published
  end;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    private { Private declarations }
    public  { Public declarations }
  end;

var
  Form1: TForm1;
//  Two:   TTwo;
  Three: TThree;

implementation

{$R *.dfm}

constructor TTwo.Create(AOwner: TWinControl);
begin
  inherited Create;
  Flbl := TLabel.Create(AOwner);
  Flbl.Parent := AOwner as TWinControl;
end;

destructor TTwo.Destroy;
begin
  Flbl.Free;
  inherited;
end;

constructor TThree.Create(AOwner: TWinControl);
begin
  inherited Create(AOwner);
  Flbl2 := TLabel.Create(AOwner);
  Flbl2.Parent := AOwner as TWinControl;
end;

destructor TThree.Destroy;
begin
  Flbl2.Free;
  inherited;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Three := TThree.Create(Self);
  Three.Flbl.Font.Style := [fsBold];
  Three.Flbl.Font.Size := 16;
  Three.Flbl.Left := 128;
  Three.Flbl.Top := 96;

  Three.Flbl2.Font.Style := [fsBold];
  Three.Flbl2.Font.Size := 16;
  Three.Flbl2.Left := 128;
  Three.Flbl2.Top := 128;

  Three.Flbl.Caption := 'Hello everybody';
  Three.Flbl2.Caption := 'Ya know it';
end;

end.
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 10730890
you're calling create inheriting it but how can you inherit a non overrided procedure? It's never inherited so....

override the TTwo and TThree constructor procedures....
0
 

Author Comment

by:tomcorcoran
ID: 10730925
How can you override the constructor since it's not virtaul in TObject?
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10731030
//.........
    public
      constructor Create(AOwner: TWinControl); dynamic;
//.........
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 10731049
ah sorry, of course...missed that it's descending from TObject....esoftbg gave the right answer....declaring it dynamic
0
 

Author Comment

by:tomcorcoran
ID: 10731070
Something is wrong in my setip. The framework takes care of creating the object and somehow the "middle" create is missed.

Cheers, Tom.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question