home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!apple!apple!mlanett
- From: mlanett@Apple.COM (Mark Lanett)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: IYourObject, Views, & ViewEdit
- Message-ID: <71159@apple.Apple.COM>
- Date: 13 Aug 92 04:54:50 GMT
- References: <1992Aug12.231336.1049@reed.edu>
- Organization: Apple Computer Inc., Cupertino, CA
- Lines: 53
-
- bowman@reed.edu (Eric Bowman (bobo)) writes:
-
- >MacApp 3.0.1 question:
-
- >I've created a window in ViewEdit with several views, including a couple of
- >subclasses of TTextListView. When I close then window, MacApp drops into
- >Macsbug to tell me that I've handed FreeIfObject an invalid object. I
- >thought the problem might be that IMyTextListView wasn't getting called.
- >This belief proved to be correct (though I have no idea if it's related to
- >the crashing...), which causes me some confusion. So I played with the
- >skeleton app, and discovered that IViewSkeleton never gets called, either.
-
- There are two ways to create objects in MacApp, procedurally or via resources.
- If you subclass a view, then to support procedural creation you write an
- I<class> routine, and *you* call it. For example:
-
- TMyTextListView* list = new TMyTextListView;
- list->IMyTextListView (myParams, doc, super, loc, size, ...);
-
- View creation via resources is different. What MacApp does is read the
- view signature and allocate an uninitialized view object. So it will allocate
- an object for TMyTextListView, but won't call IMyTextListView (it knows
- how big it is and can allocate it, but doesn't know which methods you've
- written to initialize it). Instead it will call Initialize and DoPostCreate (or
- just IRes in MacApp 2.0). So to support view creation via resources you
- override Initialize and DoPostCreate and do your own work in there. Initialize
- is normally used for setting fields to nil, DoPostCreate for allocating other
- objects. You generally override both of them. For example:
-
- pascal void TMyTextListView::Initialize () {
- inherited::Initialize(); // DON'T forget to call (FIRST!) or you will
- // have very strange errors later.
- fMyList = nil;
- }
- pascal void TMyTextListView::DoPostCreate(TDocument* doc) {
- inherited::DoPostCreate(doc);
- fMyList = NewList();
- }
-
- The reason for setting the field to nil first is a matter of safety with Free.
-
- If you need to pass some specific information to a view, then write a Set<>
- routine and call that after creating it. Set<> doesn't need to call any I<>
- routines.
-
- TWindow* wind = gViewServer->NewTemplateWindow(...);
- // MacApp calls DoPostCreate for all views
- TView* list = wind->FindSubView('list');
- if (list == nil) ProgramBreak("View resource problem - list");
- ((TMyTextListView*) list)->SetMySpecialParams(myParams);
- --
- Have a bajillion brilliant Jobsian lithium licks.
- Mark Lanett, NOT speaking for anyone. Personal opinion only.
-