Board index » delphi » Why Object References?
74133.2...@compuserve.com (Richard Knapp)
Delphi Developer |
Sat, 05 Dec 1998 03:00:00 GMT
|
74133.2...@compuserve.com (Richard Knapp)
Delphi Developer |
Sat, 05 Dec 1998 03:00:00 GMT
Why Object References?Can anyone explain why I would use Object References? If I have: type TListOfItems = class(TList); function TListOfItems.GetCurrent : TItem; Would OR help in this instance (to take care of memory issues) or is something I'm in the process of tracking down some memory stompin' and need to know Richard Knapp |
Jolyon Smit
Delphi Developer |
Sun, 06 Dec 1998 03:00:00 GMT
Re:Why Object References?QuoteRichard Knapp wrote: derived from TObject is an Object Reference - effectively a pointer to an object (but don't let anyone hear you suggest this - pointers in Delphi is a sensitive subject). This is why the following code does not work: var begin ListBox is only a reference to an object - a reference which has not been resolved in ListBox := TListBox.Create(FormObject) ; Before you attempt to access the object that ListBox refers to. I am guessing that your memory loss is being caused by objects not being freed by BTW: Might I suggest the following 'optimisation' (less typing) :-) for the function function TListOfItems.GetCurrent : TItem; All functions have a variable implicitly defined called 'Result' which is of the same I hope this helps, -- |
Richard Kna
Delphi Developer |
Mon, 07 Dec 1998 03:00:00 GMT
Re:Why Object References?Quote>The example you give is using Object References anyway. Any variable of a type Object Reference (class of TObject) is intended to serve as a 'metaclass' for this class. Hmm. That's a capability C++ does not currently have, although it can be achieved with static members. Richard |
Richard Kna
Delphi Developer |
Mon, 07 Dec 1998 03:00:00 GMT
Re:Why Object References?In <31C7CAD9.5...@platinum.com>, Jolyon Smith <sm...@platinum.com> writes: Quote>Richard Knapp wrote: Quote>I am guessing that your memory loss is being caused by objects not being freed by item. If it was outside the normal boundary (0 < iItem < Count - 1) then report a critical error and Halt. That part worked. What I wasn't doing was resetting the current item index (iItem) when I reloaded the list. In an effort to help track down the problem, I also 'nil'ed out all reference when function TList.GetItem : TItem; I've seen this have an effect under TP 6 as far as the procedure/function trying Quote>BTW: Might I suggest the following 'optimisation' (less typing) :-) for the function Quote>All functions have a variable implicitly defined called 'Result' which is of the same I'll have to get back in the books.... again! Thanks! Richard |
Nicholas Robinso
Delphi Developer |
Thu, 10 Dec 1998 03:00:00 GMT
Re:Why Object References?In article <4qbm55$...@news.internetmci.com>, Richard Knapp Quote>In <31C7CAD9.5...@platinum.com>, Jolyon Smith <sm...@platinum.com> writes: tobject in a procedure, the procedure or function will simply destroy the 4 byte object reference, not the actual object. This can be a pain when working with some components. When placing an object into a listboxes objects, freeing the object procedure Tform1.MyList; begin When the MyObject is created its data is placed somewhere and the I hope David isn;t watching... |
Richard Kna
Delphi Developer |
Fri, 11 Dec 1998 03:00:00 GMT
Re:Why Object References?Quote>Just to emphasise what Joylon smith said, when you create an item of scope rules. Quote>When placing an object into a listboxes objects, freeing the object this procedure. If you call the Free method of a list, it will call the destructor for each item in the list ( or it should) through the Free method. Now, on to the rest of the question. Does an Object Reference substitute as Richard Knapp |
Jolyon Smit
Delphi Developer |
Sat, 12 Dec 1998 03:00:00 GMT
Re:Why Object References?QuoteRichard Knapp wrote: Just one more thing tho'. In your code clip, 'oItem' ceases to exist when your function I would expect the optimiser to remove this (but have not checked) since the variable is then Just a thought. -- |
Richard Kna
Delphi Developer |
Sun, 13 Dec 1998 03:00:00 GMT
Re:Why Object References?In <31D008AC.4...@platinum.com>, Jolyon Smith <sm...@platinum.com> writes: Quote>Richard Knapp wrote: I just want to access the current item. I remember having trouble under TP 6 with pointers/refs if I did not set the reference to nil (since it tried to delete the actual item) and added that 'catch' here. Thanks again. Richard |
1. Help referencing objects based on Sender object
2. Copy Object and Reference Object?
3. Why not circular reference in VCL?
4. Why does Circular Unit Reference error exist?
5. Why "Invalid variable reference" (Helpcommand)
7. Reference counting in ole objects