I can think of a couple of ways of getting the list back and displaying it and looking after destruction.
The way I favour is to create a stringlist in the form and send the pointer to this as a parameter to your TLibrary object which merely populates it with strings and has nothing to do with creation or destruction. The form might (a) send the stringlist from a visible component or (b) create a local stringlist, send it to the TLibrary procedure, something like TLibrary.AddAllTitles(TitleStringList), and then do some processing that might include copying the list into a ListBox, usually using the Assign procedure, and then free the local stringlist. Wayne Borland's Delphi Discussion List <[email protected]> on Sunday, 21 May 2006 at 8:15 a.m. +0000 wrote: >Along with this general question, I'd like to ask one that's a little more >specific. To make responses easier, suppose you had a TLibrary class whose >only field is a list of TBook objects. TBook, in turn, contains only a >string field for titles. TLibrary.Create makes fBookList, and and >TLibrary.Destroy frees the list. Adding a book to fBookList involves either >(a) a pre-existing TBook instance or (b) creating the instance as part of a >method. ... So far so good. > >Now, suppose in the UI you want to generate a list of all the books in the >library. Since all the data manipulation should take place in a TLibrary >object, then the event handler in Form1 should probably do no more than call >a function in the object, something like TLibrary.ShowAllTitles, right? If >the event handler was going to list the books in something like a Memo, then >it makes sense that ShowAllTitles should generate a TStringList. ... So far, >still so good. > >My difficulties relate to whether or not I'd be creating memory leaks, and >understanding what needs to be freed by whom. The TStringList object created >in the last paragraph--when is it freed? Once the Memo (in Form1) has been >filled, the TStringList is no longer needed. But you can't just free it at >the end of ShowAllTitles (Form1's Memo needs the reference). And how about >all those TBook instances referenced in TLibrary's fBookList? When are they >freed? [It's probably inappropriate for this list, but these kinds of >questions get me wondering why Delphi doesn't have garbage collection.] _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

