BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Typecasting

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Students
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Thu Apr 05, 2007 11:22 pm    Post subject: Typecasting Reply with quote



What is the meaning of this syntax :
Objectname1 := ClassName (Objectname2) ;
Thanks for your help.
Back to top
Craig Stuntz [TeamB]
Guest





PostPosted: Fri Apr 06, 2007 1:17 am    Post subject: Re: Typecasting Reply with quote



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





PostPosted: Fri Apr 06, 2007 8:12 am    Post subject: Re: Typecasting Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Students All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.