f



Invalid pointer operation

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 ? 

0
Stark
6/24/2012 5:25:04 PM
comp.lang.pascal.delphi.misc 5769 articles. 1 followers. miniFAQ (1) is leader. Post Follow

5 Replies
543 Views

Similar Articles

[PageSpeed] 20

Stark wrote:
> 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 ?
  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

0
Jamie
6/24/2012 6:01:47 PM
>  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. 

0
Stark
6/24/2012 9:54:31 PM
"Stark" <franco.jommi@tin.it> wrote:

> 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.
0
JJ
6/25/2012 4:40:54 PM
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.


0
Stark
6/25/2012 9:55:38 PM
On Jun 25, 10:55=A0pm, "Stark" <franco.jo...@tin.it> wrote:
> Problem found!
> I was doing the following:
> var
> =A0 =A0TempList: TStringList;
> =A0 =A0.......................
> =A0 =A0TempList:=3D TMensiliB ( BudgetsList[i] ).GetMomths );
> =A0 =A0......................
> =A0 =A0TempList.Free;
>
> This last statement was cancelling the pointer from the list and that's w=
hy
> I was getting Invalid pointer operation in the ObjectList Free.

You have to decide/control where objects are Free'd, and make your own
rules eg

a) I'll specifically free everything

or

b) My TObjectList will free everything (defaults to true on using
Create)

If the former you must set TObjectList.OwnsObjects to false (or use
Create(false); If the latter, never Free an object in the list, or
always set the OL item to nil when you do Free one.

Alternatively you could add a Notify method to your TObjectList
descendant to do your Free'ing & Nil'ing in the object list (I think
the parent TObjectList.Free only Free's the item).

Alan Lloyd

0
alanglloyd
6/26/2012 6:04:39 AM
Reply:

Similar Artilces:

pointers, pointers, pointers...
Hi There, I came up with following sample code to demonstrate my issue: #include <18F87K22.h> #device HIGH_INTS=TRUE, adc=16, ICD=TRUE #fuses NOWDT //No Watch Dog Timer #fuses WDT128 //Watch Dog Timer uses 1:128 #fuses HSM //Hi-Speed crystal oscillator #fuses NOBROWNOUT //No brownout reset #fuses NOPLLEN //No PLL enabled #fuses BBSIZ1K //1K words Boot Block size #fuses NOXINST //Extended set extension and Indexed typedef struct{ int8 foo, test; } Th...

Pointers, pointers, pointers.......
Hi group. Asking again some help to better understand the basic principles of RPL.... In RPLMAN they say: >>>In the most general definition of RPL, I is an object pointer >>>pointing to a composite object that is the top of a stack of >>>composite objects called the runstream. >>>R points to the rest of the runstream stack. What is really meant by *the rest of the runstream* ? Is R pointing to the object right after the one pointed by I? Is R pointing to the rest of the stack *as a whole* (how's it possible?) Anything else I didn't catch? >>...

How to pass pascal string pointer to Delphi DLL?
Hi there, &nbsp; I was trying to call DLL in Labview. The declaration of this DLL in Delphi is: function YL_Write_DO(addr,tunnel,action:PChar):PChar; far;external 'ComDll.dll'; &nbsp; I need to pass Pchar(Pascal String Pointer) type inputs from Labview to the DLL. When I wire a string control to the Call Library Function Node input directly, it prompt error 1097, an exceptional error in the external node. &nbsp; My question is can I pass Pascal String Pointer to the DLL by wiring string control directly?&nbsp; If not, how to do it? I appreciate if somebody provides an e...

"Hard to understand" Invalid Pointer Operation on TCollection.Clear
Hi everyone, (i'm very sorry for my bad english) I'm developing a aplication server, that has two tasks: 1st, it must upload my clients data backup to a FTP server, and 2nd, i must check if there's updates for the client application, and download it if there's any. I'm using IdFTP as the FTP client. I inherited a class from TThread, that is TTask, and i created two classes for the two tasks, inheriting them from the TTask class. The server is working properly, running the tasks automatically. But a had to introduce a TRemoteDataModule to the server applicat...

pointer-to-pointer (invalid lvalue in unary `&)
i'm doing some Linux Kernel hacking for a course i'm currently taking. there is a pointer to a struct (struct example_struct *ex_ptr) in a .c that i want to access in a system call. i defined a pointer to a pointer in the .c: extern struct example_struct **pointer; and somewhere in the code i tried: pointer = &ex_ptr; and i get this error when trying to compile the kernel: invalid lvalue in unary `&' and it points to the line: pointer = &ex_ptr;....any idea why and what i should do to fix it? On 3 Apr 2004 09:49:41 -0800, lmachado@eden.rutgers.edu (Lucas Machado)...

Pointer-specific cache for Delphi/Reference/Pointer languages.
Hello, Delphi's classes/object instances work with pointers/references. This could mean Delphi has a level of indirection, this could mean Delphi applications perform a little bit slower when accessing objects because of this small pointer chasing problem. However these pointers are accessed frequently would be my guess. Therefore the chance of a cache hit if these pointers were stored in a special pointer cache should be pretty high, thereby making the concept of a pointer cache possibly effective. Not so with data caches. There is no garantee that the data will be accessed twic...

Overloading dereference pointers to pointers to class members operator.
Good time of the day (or night)! //===================================================================== Overloading dereference pointers to pointers to class members operator. //--------------------------------------------------------------------- Example, given below was build with BCB6 and MSVC++.NET. Both compliers allow to overload ->* formally: a) We can define binary operator function operator ->* as nonstatic member with one argument and/or as non-member function with two arguments. And we can call these functions directly. b) But any expression looks as x->*y (X x; Y y...

Pointer-to-pointer-to-pointer question
The code example below shows the dynamic allocation of a 2D array. I must admit that it took quite a while for me to get there (I already have another posting to that effect), but I am glad that I finally got it working. Now here's the problem: I am able to get the 2D array dynamically allocated correctly as long as I am doing it "in-line" (i.e. without invoking any function). The moment I try to do it in another function, I get a core dump. Any help will be appreciated. Since this function is expected to update a pointer-to-pointer type, I am actually passing the pointer-...

Pointer to pointer or reference to pointer
The way I understand it Reference To pointer as function parameter eg. void RP(int *&rpMem) {} rpMem is actually an alias for the pointer outside the function right? So I would access it exactly with the same syntax just like outside pointer right? e.g. void RP(int &*rpMem) { *rpMem = 125; rpMem++; } int Mem = 123; int *pMem = &Mem; // pMem = for example 5000 *pMem = 124; // Mem = 124; RP(pMem); // Mem = 125, pMem = 5004 Is the above correct? A <a@a.a> wrote: > e.g. > > void RP(int &*rpMem) > { > *rpMem = 125; > rpMem++; &g...

pointer vs pointer to pointer
AIM: To write a queue with 3 operations. WHAT I GOT: It works PROBLEM: Have a question: Why do "pointer to pointer" in enqueue() and "a pointer" to deleteElement() both work fine ? Will enqueue() work fine if I pass just "a pointer" to it ? Will deleteElement() work fine if I pass "pointer to pointer" ? /* A queue implementataion with the operations that I need: * (1) Add element to the front of the queue * (2) remove an element with a unique ID (string constant) * (3) compare 2 elements (string comparison) * (4) print queue * ...

Matlab, pointers and pointers to pointers
Matlab stores matrices using simple pointers in order to allocate memory. Using pointers to pointers, according to my experience, we could obtain the following benefits: - code would run faster (I think up to 70%) - memory would be allocated in a better way Why this solution is not used? There are some limitations? Luigi Luigi: <SNIP longing for pointers - not to heaven - to memory... > Why this solution is not used? There are some limitations... <luigi> a fact of life that we all have to live with: it IS just NOT happening... -or- at least it is not happening since 1984... d...

pointer to pointer
Its just a very simple and basic program to learn exactly what is described in comments here. Can you provide a better (and short) exercise ? /* A program to learn how to use a pointer to a pointer. Here we take an array of char pointers. A char* in the array, of course, points * to some char. Array has only one element. We change the value of char pointed by array's element using a function. * * VERSION 0.0 */ #include <stdio.h> void replace_char_value(char* [], char); int main(void) { char* arrc[2] = {0}; char c = 'c'; arrc[0] = &c;...

operation on pointer
1. If there is a pointer, int* ptr: int* ptr; int a = 456; p=&a; (*ptr)++; *ptr++; ++*ptr; To me, all the above three statements mean "get value of a and increment it by 1." But the printf() reveals that they are different operation on a. Could someone tell me why? 2. What differences and effects ++a and a++ have in C programming? Which one should always used? 3. Code for example: int* p; p = malloc(sizeof(int) * 50); p = p + 10; free(p); Will free(p) free all the memory allocated by "malloc" or just part of the memory malloc'ed, since p is not pointing the be...

Pointers to pointers
How can you use a "pointer to a pointer" as a two dimensional array using 'new' and 'delete' rather than 'malloc' and 'free'? Thanks, Jonas Jonas Cord wrote: > How can you use a "pointer to a pointer" as a two dimensional array > using 'new' and 'delete' rather than 'malloc' and 'free'? Pretty much the same. int main() { int** data; data = new int*[100]; for (int i = 0; i < 100; ++i) data[i] = new int[100]; //use it for (int i = 0; i < 100; ++i) delete []...

Web resources about - Invalid pointer operation - comp.lang.pascal.delphi.misc

Operation Gladio - Wikipedia, the free encyclopedia
Operation Gladio ( Italian : Operazione Gladio ) is the codename for a clandestine NATO " stay-behind " operation in Italy after World War II ...

Police operation in Chandler Street, Belconnen
... tense scenes between a man and police. Police say officers who swarmed a Belconnen street on Wednesday morning were engaged in a routine operation, ...

Police operations at Sydney schools after threats
Up to eight operations are under way at Sydney schools, as police investigate &quot;possible threats&quot;, NSW police have confirmed.

Perth's worst drivers to get letter from Commissioner for Operation Communique
Perth's worst-behaved drivers can expect a text message or letter from the WA Police Commissioner next month pleading with them to wise up. ...

How a ‘Half-Baked Little Operation’ Turned into a Billion Dollar News Channel
... into MSNBC. You had CNN which was a worldwide brand. They both had unlimited resources. And then Rupert with a kind of half-baked little operation ...

China's Money-Market Operations Inject Most Cash in Three Years
China’s central bank used this week’s two money-market operations to add the most funds to the financial system in three years, helping to prevent ...

Secretive operation nets dozens of cartel members
CBS News Secretive operation nets dozens of cartel members CBS News TUCSON, Ariz. - Joaquin "El Chapo" Guzman's cartel took another massive ...

Luetkemeyer And Hensarling Work To Prevent The Next Operation Choke Point
Congress is taking the necessary steps to ensure Operation Choke Point does not rise from the dead.

Lite-On Technology to focus 2016 operations on 5 areas
EMS provider Lite-On Technology will transform its business operations in 2016 with a focus on five areas: cloud technologies, LED lighting, ...

Xerox Decides to Split Into Separate Document, BPO Operations
Xerox to split into independent document, BPO companies; Google's Chrome browser may soon mark HTTP sites unsafe; Microsoft releases Cordova ...

Resources last updated: 2/2/2016 5:47:58 PM