My thanks to Rob, Wayne, Luthfi, and Scott for their responses to my last 
post. It was easy to synthesize what each of you said--quite instructive. If 
it's OK by y'all, I'm going to keep asking occasional Q's on the topic. I 
find resources about object oriented design, but it's a little hard for me 
to translate them to Delphi. I've got a bunch of Q's below. Please don't 
feel compelled to respond to all of them :-)

First, I'm confused now about freeing memory and also about understanding 
what's passed, memory-wise, by parameters in methods ("x:TSomething" vs. 
"var x:TSomething" vs "const x:TSomething") ...

Next, to help me understand OOP, I made a small app. It simply manipulates 
attributes on a list of objects--books in a library, members of a club, 
whatever. I'm using people objects, but it could be anything. I could 
accomplish this task by dropping a few data aware controls on a form, 
connecting them to a dataset, and writing event handlers. To learn, I'm 
approaching the task in a more OOP-centric manner.

So, I created a base class (TPerson) with a few attributes, a class to work 
with groups of TPerson objects (TPeople), and a user interface class (TGUI).

I also created TPeople.SaveToFile and .LoadFromFile methods, but let's 
suppose I wanted to put the code into another class--someday I could decide 
to load/save info with a different file format, so it would be good to have 
persistence stuff separate from everything else.

Currently, the TGui class creates and ultimately frees a global instance of 
TPeople. TPeople creates a list of TPerson objects.

Assume that the Save code will iterate through the items in TPeople and save 
each object's fields. So, I assume that TGui calls TPeople's SaveToFile 
method (passing in a filename string), which in turn calls a method in the 
new class (TPersistTheCollection).

Would TPeople.SaveToFile create a new instance of TPersistCollection, and 
iterate through a loop passing each member of the TPeople list to 
TPersistTheCollection (a pointer to the list member? a copy of the object?), 
and then Free the instance?

And then how would the Load method work? What's passed from 
TPersistTheCollection?

Finally, are objects ever used as parameters in methods? If so, where are 
these object instances usually freed?

As always, my sincere thanks to you all. You're my teachers! -- Al C. 
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to