Solved

Constructor on TObject descendant

Posted on 2004-04-01
9
525 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 64
add combobox item based on numbers 9 144
Delphi: how to implement a User Shortcut mapper? 1 110
How to load 2 images in same column in Delphi 2 47
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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