 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ed Evans Guest
|
Posted: Tue Jun 22, 2004 10:51 pm Post subject: Strange EInvalidTypecast exceptions |
|
|
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
|
Posted: Wed Jun 23, 2004 9:51 pm Post subject: Re: Strange EInvalidTypecast exceptions |
|
|
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.
|
|
| 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
|
|