[comp.sys.mac.programmer] Another C++/MacApp question: Each

mkb@rover.ri.cmu.edu (Mike Blackwell) (10/01/90)

I have another question about using MacApp with C++, involving the Each
method. I'm aware that this is discussed briefly in the August MacTutor, but
I still can't figure it out. It is also apparently discussed in the MacApp
2.0 final docs, but due to a screwup, I only have the beta docs and I'm
still trying to get that fixed.

I'm going through the 2.0 tutorial, but coding in C++. The problem I have
stems from the following Object Pascal:

PROCEDURE TIconDocument.RedrawViews;
    PROCEDURE InvalidateView (aView: TView)
    BEGIN
        aView.ForceRedraw;
    END;
BEGIN
    ForAllViewsDo(InvalidateView);
END;

I realize I need to use static links to get the parameters passed in C++,
and I've been trying variations on the theme:

pascal void InvalidateView(TView *aView)
{
    aView->ForceRedraw();
}

typedef pascal void (*DoToView)(Tview *aView, void *DoToView_StaticLink);

pascal void TIconDocument::RedrawViews(void)
{
    ForAllViewsDo((DoToView)InvalidateView);
}

... but I can't seem to divine the correct syntax. Any help in this matter
will be greatly appreciated (and I hope I get my docs soon!).

		Mike Blackwell		mkb@rover.ri.cmu.edu

mdtaylor@Apple.COM (Mark David Taylor) (10/06/90)

In article <10615@pt.cs.cmu.edu> mkb@rover.ri.cmu.edu (Mike Blackwell) writes:
>I have another question about using MacApp with C++, involving the Each
>method.
>I'm going through the 2.0 tutorial, but coding in C++.

The C++ version of IconEdit is provided in the "Unsupported Goodies" folder
of the MacApp 2.0 CD Release, also available on the ETO disk (yet another
reason to get ETO!)  The following code is taken from there:

Longint	NullStaticLink;	// Use &NullStaticLink when a static link

pascal void InvalidateView (TView* aView, void* InvalidateView_StaticLink)
{
	aView->ForceRedraw();	// Cause the view to be redrawn.
}

pascal void TIconDocument::RedrawViews()
{
	ForAllViewsDo(InvalidateView, &NullStaticLink);
		// Invalidate each of the doc's views.
}

Of course, in other cases involving static links, such as when you provide
a Compare function for a call to a subclass of TSortedList->Search(), you
can actually pass something useful instead of NullStaticLink.

I should also refer you to the excellent discussion of converting nested
procedures to C++ by Keith Rollin in tech note #265.

Hope this helps.

- Mark