Topic: Each function


Author: fall@disuns2.epfl.ch (Saloum Fall)
Date: 30 Sep 91 11:36:59 GMT
Raw View

Hello there,

It's me again with my "Each" method.
Permit me to remember you my different objects and methods:

1)The interface for the "Each" method is :(from the file UList.h)
virtual pascal void
Each(pascal void (*DoToItem)(TObject *item, void *DoToItem_StaticLink),
     void *DoToItem_StaticLink);

Here is a little description of the two objects i use for test:
2) TMyObject whose only job is to return the name of the object:
pascal Str255  *TMyObject::TheName() {return (Str255 *)this->fName;}

3) TTest is an object who has a field "TList* fMyList", and who provides
the following method:
pascal void TTest::EachDo(pascal void DoThis(TObject *anObject, void *))
{fMyList->Each(CallIt, (void *)DoThis);}

Finally i have a function Affiche() who belongs to no object:
pascal void Affiche(TObject *anObject, void *) {
// do nothing rigth now
// will draw the string returned by the preceeding function TheName()
}

__________________________________

What i want to do is to apply this last function to each element (same type as
TMyObject) of the list which is pointed by the fMyList field of a TTest object.

I wrote the following function :
pascal void CallIt(TObject *anObject, void *link) {
(*((TestProc *) link)) (anObject);
}

finally i called my method with the instruction : aTest->EachDo(Affiche);
As you can guess i have no problem at the compilation, but while running my
program under the control of the debugger i always get this error :

Exception #3 exception frame Address = $00400BCA
PC = ..
Address error : Word or long-word reference mode to an odd address
Bad address was : $00403C6C
Stopped at SysErr

Do you think that the link parameter of the function CallIt is set if we don't
explicitly initialize it ?

PS:Let me tell you that i've verified that all my objects were well
initialized.
_____________________________________

I hope that you will be able to help me.
Sorry for all my english mistakes.
Hope to read you soon.
Thanks.
fall@disuns2.epfl.ch