|
|||
|
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 ? |
|
|
||||
|
||||
|
|
|
|||
|
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 |
|
|||
|
> 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. |
|
|||
|
"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. |
|
|||
|
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. |
|
|||
|
On Jun 25, 10:55*pm, "Stark" <franco.jo...@tin.it> wrote:
> 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. 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 |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|