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 

Strange EInvalidTypecast exceptions

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





PostPosted: Tue Jun 22, 2004 10:51 pm    Post subject: Strange EInvalidTypecast exceptions Reply with quote



I've got an odd situation that raises a typecast exception.

I have a couple types in a pas file:
TFooBase = class
// blah
end;

TFoo = class(TFooBase)
// more blah
end;

This pas file is seperately compiled into a package and an exe
project. The package has a method like:
function MakeFoo(): TFooBase;
begin
result := TFooBase.Create();
end;

When the exe runs, it loads the package via LoadPackage, and
eventually calls MakeFoo like this:
procedure someproc();
var
fooBase: TFooBase;

begin
fooBase := MakeFoo();
Assert( fooBase.ClassName = 'TFoo' ); // This works
Assert( foo is TFoo ); // This fails
end;

Any ideas?

Cheers,
Ed Evans
Back to top
Zakath
Guest





PostPosted: Wed Jun 23, 2004 9:51 pm    Post subject: Re: Strange EInvalidTypecast exceptions Reply with quote





Ed Evans wrote:

Quote:
I've got an odd situation that raises a typecast exception.

I have a couple types in a pas file:
TFooBase = class
// blah
end;

TFoo = class(TFooBase)
// more blah
end;

This pas file is seperately compiled into a package and an exe
project. The package has a method like:
function MakeFoo(): TFooBase;
begin
result := TFooBase.Create();
end;

When the exe runs, it loads the package via LoadPackage, and
eventually calls MakeFoo like this:
procedure someproc();
var
fooBase: TFooBase;

begin
fooBase := MakeFoo();
Assert( fooBase.ClassName = 'TFoo' ); // This works
Assert( foo is TFoo ); // This fails
end;

Any ideas?
//If you add a new

type
TFooClass = class of TFooBase;

//And then modify MakeFoo
function MakeFoo(FC: TFooClass): TFooBase;
begin
result := FC.Create();
end;

//You can then test it with (works for me)
var
fooBase: TFooBase;
begin
fooBase := MakeFoo(TFoo);
Assert(fooBase.ClassName = 'TFoo');
Assert(fooBase is TFoo);
fooBase.Free;
end.



Quote:

Cheers,
Ed Evans

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi ObjectPascal 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.