Re: Many questions about partially constructed objects !!!???
- From: "Skybuck" <skybuck2000@xxxxxxxxxxx>
- Date: 1 Jul 2006 16:20:46 -0700
Yes Maarten,
I agree with your story and design decisions etc. I, just like you,
like to keep constructors as simple as possible to prevent any nasty
problems because constructors are a bad place to have problems as this
example more or less illustrates. When the constructors fails the whole
object construction fails which makes it as good as impossible to fix
any little problems inside the object. With your design and special
methods it's still possible to fix or investiage any little problems so
it's more flexible.
However your/this design has limitations. It's more difficult to write
abstract/general code/objects/classess which can create other objects
and classess. To do so there needs to be a common framework and the
only common framework is delphi's constructor/destructor framework.
Your design for example is only your design/framework... if I use your
design for example... then the design can no longer create any other
objects because those do not have the necessary framework in place.
This is related to my other post about passing a constructor. If that
was possible then it would be possible to write functions which can
generate any kind of object. Delphi can already do this ofcourse... the
problem is with special constructors which have/need parameters.
The problem I now face is the following:
I want to create and object. This object has an array of byte. The
array of byte also has to be allocated. I would like to do this in the
constructor so that it's an all or nothing situation. If everything
gets allocated then I can use the object. If some part fails then I
have no use for the object.
So I would like to pass a parameter to the constructor... and maybe I
even want to write a function like so:
function CreateObject( const ParaClassType : Tclass; var ParaObject :
Tobject ) : boolean;
begin
try
ParaObject := ParaClassType.Create;
result := true;
except
result := false; // hopefully inherited create/access violation
exception won't cause a
failure here..
// probably not since Tobject probably
catches it...
end;
end;
I saw your post in the other thread... but I don't like assembler at
all... also it seems to pass longwords only ? Well that will do for
now... but general parameters would be cooler... maybe variants can
help ?
Anyway I'll check out your code to see if I understand some of it and
how it works..
Bye,
Skybuck
.
- Follow-Ups:
- Re: Many questions about partially constructed objects !!!???
- From: Maarten Wiltink
- Re: Many questions about partially constructed objects !!!???
- From: Skybuck
- Re: Many questions about partially constructed objects !!!???
- References:
- Many questions about partially constructed objects !!!???
- From: Skybuck
- Re: Many questions about partially constructed objects !!!???
- From: Maarten Wiltink
- Many questions about partially constructed objects !!!???
- Prev by Date: Create, Free, Create, Free <- access violation ? Huh ?
- Next by Date: Re: Many questions about partially constructed objects !!!???
- Previous by thread: Re: Many questions about partially constructed objects !!!???
- Next by thread: Re: Many questions about partially constructed objects !!!???
- Index(es):
Relevant Pages
|