Re: [fpc-devel] How to force the child's constructor to call its parent constructor

2007-10-22 Thread Michael Schnell
Couldn't you check the ID in your after construction event and throw an 
exception if it's not set ?


-Michael
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] How to force the child's constructor to call its parent constructor

2007-10-22 Thread amir
It is a run-time error but what I am looking for is an compile-time 
error. It is not sensible(for me) to raise an exception because of bad 
implementation. Thanks for you idea ;)


Amir

Michael Schnell wrote:
Couldn't you check the ID in your after construction event and throw 
an exception if it's not set ?


-Michael
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


[fpc-devel] How to force the child's constructor to call its parent constructor

2007-10-21 Thread amir
Is there any way to force the child constructor to call its 
parent(direct parent) constructor. Consider the following case:


 TParent= class (TObject)
 private
   ID: Integer;
 public
 constructor Create (MyIdentifier: Integer);

 end;

I want to force the all childs of TParent to call the Create constructor 
(with appropriate parameter). But one can implement a child class like this:

 constructor TChild.Create;
 begin
// do any thing but not use inherited.
 end;


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] How to force the child's constructor to call its parent constructor

2007-10-21 Thread Joao Morais

amir wrote:
I want to force the all childs of TParent to call the Create constructor 
(with appropriate parameter). But one can implement a child class like 
this:

 constructor TChild.Create;
 begin
// do any thing but not use inherited.
 end;


No way. But you can override the NewInstance method; constructors will 
call it for sure. You can also override the AfterConstruction method.


--
Joao Morais
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] How to force the child's constructor to call its parent constructor

2007-10-21 Thread amir


Joao Morais wrote:

amir wrote:
I want to force the all childs of TParent to call the Create 
constructor (with appropriate parameter). But one can implement a 
child class like this:

 constructor TChild.Create;
 begin
// do any thing but not use inherited.
 end;


No way. But you can override the NewInstance method; constructors will 
call it for sure. You can also override the AfterConstruction method.


--
Joao Morais
How can I use the NewInstance or AfterConstruction methods for my 
purpose? I want to force the others to set ID. The TParent is written by 
me but anyone can write the TChild class.



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel