Re: Strange EAccessViolation which I cannot figure out...



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

.



Relevant Pages

  • Re: ShellExecAndWait and ExecAndWait functions with Office XP
    ... procedure adtBitBtn1Click(Sender: TObject); ... procedure ShellExecAndWait(dateiname: string; Parameter: string); ... Result:= CreateProcess(nil, PChar(CmdLine), nil, nil, FALSE, ... nil, {Pointer to Application} ...
    (borland.public.delphi.nativeapi)
  • ExecAndWait with MS Word XP
    ... procedure adtBitBtn1Click(Sender: TObject); ... procedure ShellExecAndWait(dateiname: string; Parameter: string); ... Result:= CreateProcess(nil, PChar(CmdLine), nil, nil, FALSE, ... nil, {Pointer to Application} ...
    (borland.public.delphi.nativeapi)
  • Re: ExecAndWait with MS Word XP
    ... procedure adtBitBtn1Click(Sender: TObject); ... > procedure ShellExecAndWait(dateiname: string; Parameter: string); ... Result:= nil ... nil, {Pointer to Application} ...
    (borland.public.delphi.nativeapi)
  • Re: Crashes in Debug (random) but not release
    ... The parameter is passed as a contant string (ex: ... an invalid pointer arrives at the copy ... >Who wrote the constructor? ... >>> Boston, MA 02118 ...
    (microsoft.public.pocketpc.developer)
  • Re: Arrays of Class Objects
    ... > In your original constructor one had to pass a 'string'. ... The compiler cannot create an Element Object from a string literal ... Element(const char* arg) ... When you are assigning a pointer to std::string you need to make sure ...
    (alt.comp.lang.learn.c-cpp)