Article View: comp.os.msdos.programmer
Article #84Re: Help! How do I use the forEach method in Borland's Bag class?
From: ERIC TREPANIER
Date: Mon, 02 Nov 1992 15:39
Date: Mon, 02 Nov 1992 15:39
54 lines
2037 bytes
2037 bytes
In article <1992Nov2.030927.14309@njitgw.njit.edu> dic5340@hertz.njit.edu (David Charlap) writes:
>A am using Borland C++ 3.1 for Windows. I managed to declare an
>object of type Bag to store assorted objects in. Now, I want to call
>a certain member function (the paint method) on each object in the
>bag.
Well the manual is correct, though perhaps obscure about what is considered
an "iterFuncType". What you need to do is declare a global function
taking a reference to an object (Object&) and a void pointer which may be
used to acces optionnal arguments. If you want the "iterFuncType" to be a
private member of the class, you will need to declare it "static".
For example:
class Child: public TWindow
{
...
}
class MainWnd: public TWindow
{
// fooBag is a collection of Child objects
PBag fooBag;
...
virtual void Paint(HDC, PAINTSTRUCT&);
static void PaintKids(Object&, void*);
...
}
void MainWnd::Paint(HDC PaintDC, PAINTSTRUCT& PaintInfo)
{
...
// Call each Child object's Paint method with PaintInfo as argument
fooBag->forEach(PaintKids, &PaintInfo);
...
}
void MainWnd::PaintKids(Object& o, void* p)
{
PAINTSTRUCT *ps = p;
((Child&) o).Paint(ps->hdc, *ps);
}
Hope this is useful.
Eric
--
Eric Trepanier
eric@tgm.CAM.ORG
"Everybody has a right to believe in something.
I believe I'll have another beer."
Technical Details
Message-ID:
<Bx3I61.450@DMI.USherb.CA>Path:
arc1-ca.pugleaf.net!sparky!uunet!utcsri!newsflash.concordia.ca!garrot.DMI.USherb.CA!trepe00References:
<1992Nov2.030927.14309@njitgw.njit.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer,comp.os.ms-windows.programmer.tools,comp.os.ms-windows.programmer.misc Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!newsflash.concordia.ca!garrot.DMI.USherb.CA!trepe00 From: trepe00@DMI.USherb.CA (ERIC TREPANIER) Subject: Re: Help! How do I use the forEach method in Borland's Bag class? Message-ID: <Bx3I61.450@DMI.USherb.CA> Sender: usenet@DMI.USherb.CA (Pour courrier Usenet) Nntp-Posting-Host: roselin Organization: Universite de Sherbrooke -- Dept. d'Informatique References: <1992Nov2.030927.14309@njitgw.njit.edu> Date: Mon, 2 Nov 1992 15:39:36 GMT Lines: 54