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 

TReader with Collections - two problems

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Ashley Berlin
Guest





PostPosted: Sat Jul 26, 2003 5:32 pm    Post subject: TReader with Collections - two problems Reply with 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


Back to top
Maynard Philbrook
Guest





PostPosted: Sat Jul 26, 2003 6:02 pm    Post subject: Re: TReader with Collections - two problems Reply with quote



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





PostPosted: Sun Jul 27, 2003 4:40 am    Post subject: Re: TReader with Collections - two problems Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) 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.