 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Thu Apr 05, 2007 11:22 pm Post subject: Typecasting |
|
|
What is the meaning of this syntax :
Objectname1 := ClassName (Objectname2) ;
Thanks for your help. |
|
| Back to top |
|
 |
Craig Stuntz [TeamB] Guest
|
Posted: Fri Apr 06, 2007 1:17 am Post subject: Re: Typecasting |
|
|
amir.e (AT) softhome (DOT) net wrote:
| Quote: | What is the meaning of this syntax :
Objectname1 := ClassName (Objectname2) ;
|
It tells the compiler: "I am absolutely positive that Objectname2 is
of a class which can be assigned to a reference of the declared type of
Objectname1, so you should ignore all type checking and just go ahead
and do the assignment."
E.g.:
var
Obj: TObject;
Foo1, Foo2: TFoo;
begin
Foo1 := TFoo.Create;
Obj := Foo1; // OK; TFoo is a subclass of TObject
Foo2 := Obj; // not OK; TObject <> TFoo, nor does TObject
// inherit from TFoo
Foo2 := TFoo(Obj); // OK, since we know that Obj currently
// contains an instance of TFoo
This is dangerous if you're not absolutely positive of the type of the
instance.
--
Craig Stuntz [TeamB] · Vertex Systems Corp. · Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
IB 6 versions prior to 6.0.1.6 are pre-release and may corrupt
your DBs! Open Edition users, get 6.0.1.6 from http://mers.com |
|
| Back to top |
|
 |
Amir Guest
|
Posted: Fri Apr 06, 2007 8:12 am Post subject: Re: Typecasting |
|
|
On Apr 6, 12:17 am, "Craig Stuntz [TeamB]" <craig_stu...@nospam.please
[a.k.a. acm.org]> wrote:
| Quote: | ami...@softhome.net wrote:
What is the meaning of this syntax :
Objectname1 := ClassName (Objectname2) ;
It tells the compiler: "I am absolutely positive that Objectname2 is
of a class which can be assigned to a reference of the declared type of
Objectname1, so you should ignore all type checking and just go ahead
and do the assignment."
E.g.:
var
Obj: TObject;
Foo1, Foo2: TFoo;
begin
Foo1 := TFoo.Create;
Obj := Foo1; // OK; TFoo is a subclass of TObject
Foo2 := Obj; // not OK; TObject <> TFoo, nor does TObject
// inherit from TFoo
Foo2 := TFoo(Obj); // OK, since we know that Obj currently
// contains an instance of TFoo
This is dangerous if you're not absolutely positive of the type of the
instance.
--
Craig Stuntz [TeamB] · Vertex Systems Corp. · Columbus, OH
Delphi/InterBase Weblog :http://blogs.teamb.com/craigstuntz
IB 6 versions prior to 6.0.1.6 are pre-release and may corrupt
your DBs! Open Edition users, get 6.0.1.6 fromhttp://mers.com
|
Dear
Thanks for your complete answer,
you explained clearly . |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|