Re: Strange EAccessViolation which I cannot figure out...
- From: Ikke <ikke@xxxxxxx>
- Date: Wed, 09 May 2007 09:59:40 GMT
Jamie <jamie_ka1lpa_not_valid_after_ka1lpa_@xxxxxxxxxxx> wrote in
news:Pc80i.69$xr4.60@xxxxxxxxxxxx:
<snip>
#1.
You need a constructor, never assume that an object in a class
is always NILL just because you know you haven't created it yet.
Testing for NIL on an object pointer to check for verification of
a valid or not yet created object is not a good thing, how ever, it
does work ok if you design your code such that if for example, some
where in your code you are freeing and setting it to NIL to then later
on test for this condition to insure it is valid before using it...
The proper way is to always create it in the constructor or, Set it
to NIL so that proper flow can be had.
Thanks for the advice - I've already replied to Tom with the necessary
changes, and I've indeed added constructor/destructor code.
Am I correct in assuming that a newly created, empty TObjectList still
takes up memory? If so, then I prefer to set the TObjectList to nil,
rather than creating a new one.
#2.
In your OutputDebugString(pchar(dbls.count)); is incorrect use of.
The dbls.counts yields a integer type, you have implied with a
type cast around this returned value as a pointer to a pchar string.
All this is going to do is generate a pointer to a memory location
address if which value, is the "COUNT" return "Number of items"
for example, if you have 6 items in the list, this will generate an
address of 6. this is most definitely out of your address space..
I think what you meant to do is this.
OutputDebugString(pchar(IntTostr(dbls.count)));
Indeed - an oversight on my part. In the AddDoubles procedure I had it
the right way round. Thanks for pointing this out!
The INtTostr(...) generates a Delphi long string.,These types of
strings are referenced via a pointer. so the return value is a pointer
to the start of the first character of a delphi string.
Type casting the Pchar around it makes the DebugString function
happy
into thinking it's looking at it's type of string..
etc...
The good news is that I've changed the call to IntToStr(dbls.count), the
bad news is that I still get the error :(
Thanks,
Ikke
.
- References:
- Prev by Date: Re: Strange EAccessViolation which I cannot figure out...
- Next by Date: Re: Strange EAccessViolation which I cannot figure out...
- Previous by thread: Re: Strange EAccessViolation which I cannot figure out...
- Next by thread: Re: Strange EAccessViolation which I cannot figure out...
- Index(es):
Relevant Pages
|