Well, a day later I realized that I can address the issues I'm talking about below by simply having one class for the collection (TPeople), and have classes with SaveToFile and LoadFromFile methods that derive from TPeople. Each derived class could use different ways to persist data ... much simpler than I was thinking about below. ... Still, I'd love to get insight into the issues I mentioned, esp. related to how or when objects are passed between methods in different objects, e.g., passing string lists to or from a procedure ...

From: "Alan Colburn" <[EMAIL PROTECTED]>
Reply-To: Borland's Delphi Discussion List <[email protected]>
To: "Borland's Delphi Discussion List" <[email protected]>
Subject: Learning OOP (part 3)
Date: Fri, 26 May 2006 11:18:52 -0700

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

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to