Discussion:
Invalid pointer operation
(too old to reply)
Stark
2012-06-24 17:25:04 UTC
Permalink
I get the error message on this line of the FormClose:
BudgetsList.Free;

This is an TObjectList which is so declared (together with the TMonthly
class whose instances then are added to the list):
var
BudgetsList: TObjectList;
oMonthly: TMonthly;

It is used as follows::

BudgetsList:= TObjectList.Create(true);
do while ....
oMonthly:= TMonthly.Create(...);
BudgetsList.Add(oMonthly);
end;

As soon as I close the form I get the Invalid pointer operation error; I
insist in closing the form and after two or three attempts it closes.Any
idea ?
Jamie
2012-06-24 18:01:47 UTC
Permalink
Post by Stark
BudgetsList.Free;
This is an TObjectList which is so declared (together with the TMonthly
var
BudgetsList: TObjectList;
oMonthly: TMonthly;
BudgetsList:= TObjectList.Create(true);
do while ....
oMonthly:= TMonthly.Create(...);
BudgetsList.Add(oMonthly);
end;
As soon as I close the form I get the Invalid pointer operation error; I
insist in closing the form and after two or three attempts it closes.Any
idea ?
If you free any of the objects in the list during your application run
time, you want to remove the entry from the list. Otherwise, when you
terminate your program, an attempt is main to call the TObject.Free
members of each item in the list and if you have not removed it from the
list, the pointer value of the old object is still there, even though it
no longer is valid.

Last time I looked, the TobjectList class cycles through the list of
non nil pointers and calls the "Tobject.Free" for each
entry. This is done when you destroy the TObjectList instant..

Jamie
Stark
2012-06-24 21:54:31 UTC
Permalink
Post by Jamie
If you free any of the objects in the list during your application run
time, you want to remove the entry from the list. Otherwise, when you
terminate your program, an attempt is main to call the TObject.Free
members of each item in the list and if you have not removed it from the
list, the pointer value of the old object is still there, even though it
no longer is valid.
Last time I looked, the TobjectList class cycles through the list of non
nil pointers and calls the "Tobject.Free" for each
entry. This is done when you destroy the TObjectList instant..
Jamie
There are no free at runtime.. The list count is correct before the free,
then raises the error. After the second attempt to close the form, the count
goes to 3 and then to 0.
JJ
2012-06-25 16:40:54 UTC
Permalink
Post by Stark
There are no free at runtime.. The list count is correct before the
free, then raises the error. After the second attempt to close the form,
the count goes to 3 and then to 0.
It could be that at the time before it was freed, the memory structure is
already broken. Try the same test using TStringList for the list, and a
string as the month.
Stark
2012-06-25 21:55:38 UTC
Permalink
Problem found!
I was doing the following:
var
TempList: TStringList;
.......................
TempList:= TMensiliB ( BudgetsList[i] ).GetMomths );
......................
TempList.Free;

This last statement was cancelling the pointer from the list and that's why
I was getting Invalid pointer operation in the ObjectList Free.
a***@aol.com
2012-06-26 06:04:39 UTC
Permalink
This post might be inappropriate. Click to display it.
Loading...