Solved

Constructor on TObject descendant

Posted on 2004-04-01
9
527 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
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!

 
LVL 12

Accepted Solution

by:
esoftbg earned 50 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 22

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 22

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connection between libmysql.dll and MySQL Versions 7 119
How to call a form that is in a DLL  from an application? 13 87
Dev Express grid collapse 2 47
DBGrid or StringGrid ? 6 120
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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