 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ashley Berlin Guest
|
Posted: Sat Jul 26, 2003 5:32 pm Post subject: TReader with Collections - two problems |
|
|
I've been using TReader and TWriter to write a collection to a file -
i'm using it to store settings.
I have ben constantly getting a code guard error whenever i create a reader
TReader* Reader = new TReader(fs, 4096);
// fs i an opened TFileStream
I get the following code guard error:
Method called on illegally casted object:
Attempt to access 128 byte(s) at 0x0412B228. The 'this' pointer points
to heap block 0x0412B228 which is only 124 bytes long.
I was horrified to discover that
int sz = sizeof(TReader) - InstanceSize(__classid(TReader));
returns a value of 4 - i.e. sizeof(TReader) is four bytes larger than it
should be! I have found a solution to this, but i dont like it:
In Classes.hpp i placed #pragma pack(4) .. #pragma pack() directives
around the definition of TReader and TWriter (same problem). How much
of a bad idea is this?
The other problem I have been having is that it does not read the count
properly: Collection->Count always says 1, however
Collection->FItems->Count returns the correct value? Any clues to
solving this one?
Thanks in advance
Ash Berlin
|
|
| Back to top |
|
 |
Maynard Philbrook Guest
|
Posted: Sat Jul 26, 2003 6:02 pm Post subject: Re: TReader with Collections - two problems |
|
|
that is not correct.
use the size(Reader) instead..
it will return the size of the instance which is 4 bytes.
what your getting is the size of the Class it self and is not valid for what
your doing.
InstanceSize is the actual size of the allocated chuck of memory new creates
for the
class.
the class code is different from the instance code when using Pointer types
/Dynamic types.
ect..
Ashley Berlin wrote:
| Quote: | I've been using TReader and TWriter to write a collection to a file -
i'm using it to store settings.
I have ben constantly getting a code guard error whenever i create a reader
TReader* Reader = new TReader(fs, 4096);
// fs i an opened TFileStream
I get the following code guard error:
Method called on illegally casted object:
Attempt to access 128 byte(s) at 0x0412B228. The 'this' pointer points
to heap block 0x0412B228 which is only 124 bytes long.
I was horrified to discover that
int sz = sizeof(TReader) - InstanceSize(__classid(TReader));
returns a value of 4 - i.e. sizeof(TReader) is four bytes larger than it
should be! I have found a solution to this, but i dont like it:
In Classes.hpp i placed #pragma pack(4) .. #pragma pack() directives
around the definition of TReader and TWriter (same problem). How much
of a bad idea is this?
The other problem I have been having is that it does not read the count
properly: Collection->Count always says 1, however
Collection->FItems->Count returns the correct value? Any clues to
solving this one?
Thanks in advance
Ash Berlin
|
--
To See what real programmers do in their spare time visit
http://jamie12.home.mindspring.com
home of PC bit software ..
Please send comments about my work .
|
|
| Back to top |
|
 |
Fishface Guest
|
Posted: Sun Jul 27, 2003 4:40 am Post subject: Re: TReader with Collections - two problems |
|
|
Ashley Berlin wrote:
| Quote: | I was horrified to discover that
int sz = sizeof(TReader) - InstanceSize(__classid(TReader));
returns a value of 4 - i.e. sizeof(TReader) is four bytes larger than it
should be! I have found a solution to this, but i dont like it:
|
Any chance you are running into this?
http://groups.google.com/groups?threadm=3ca44f1c_1%40dnews
|
|
| 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
|
|