From: ppollet@cismibm.univ-lyon1.fr (Patrick POLLET)
Newsgroups: comp.lang.pascal
Subject: Re: Need Help with Resource and Init
Date: Wed, 27 Jan 1993 09:19:08 GMT
Organization: INSA  CENTRE INFORMATIQUE DU 1er CYCLE
NNTP-Posting-Host: pc110-02.insa-lyon.fr

In article <1993Jan26.223719.16694@a.cs.okstate.edu> greaham@a.cs.okstate.edu (GREAHAM DARIN DONA) writes:
>From: greaham@a.cs.okstate.edu (GREAHAM DARIN DONA)
>Subject: Need Help with Resource and Init
>Date: Tue, 26 Jan 93 22:37:19 GMT



>   I am attempting to place a derivation of a dialog box's Init constructor
>into a resource file.  The problem that arises is that the HandleEvent for
>the dialogbox no longer works.  I seem to be doing something dreadfully
>wrong but can't quite put my finger on it.  Simple type declaration:

>   Type 
>     PBox = ^TBox;
>     TBox = Object(TDialog)
>        constructor Init;
>        destructor ...
>        procedure HandleEvent...
>     end;


>   Now that the Init is all in a resource file, using 
>          Box := New(PBox,Init)

>   won't work, of course.  But
>          Box := PBox(ResFile.Get('DialogBox'));

>   will but the HandleEvent doesn't respond.  I'm not for sure what to do
>past this point.  I've tried numerous things but nothing works.

>BTW: The dialog box that is in the resource file is NOT inherited from 
>     PBox, should it?? 



>   Thanks for any help.

>   Darin...

    If you place a DESCENDANT of tDialog in a ressource, as it seems you
try to do it, YOU MUST register that descendant using a tStreamRec record
with an object ID different of the object ID of tDialog (10 I think).
    
 Something like:
   
   Const RMyBox:tStreamRec=
          ObjType: 200;         <=== whatever unique number > 100 
          Vtmlink:ofs(TypeOf(TMyBox));
          Load:@tMyBox.load;     <=== even if you do not overloaded them
          Store:@tMyBox.Store    <===   "      "      "      "        "
         end; 

   And in your program you must register that new object by
     RegisterType(rMyBox) .
       This must be done :
          -in the program that wrote that object to a stream
          -in the program that reads it back ( likely you real
              application)   
  
   The point of this is to WRITE at the beginning of the image of the 
box in the stream the ID 200 (for your box) and not the ID 10 (for 
tDialog)

    When you application READS back the box from the stream , it should see 
ID=200 and uses that value to search the tStreamRecs list and find a match 
with your Rbox tstreamrec . That will determine what VTM to use for your 
box and especially the REAL ADDRESS of the overloaded HandleEvent() method.
If you did not do it, the ID=10 will be found and the standard VTM of
tDialog will be used. And all the virtual methods will be resolved to
those of tDialog and not to yours ....

Hope I have been clear ( not sure ....)
ppollet@cismibm.univ-lyon1.fr (Patrick POLLET)
--------------------------------------------------------
Dr Patrick L.Pollet
Institut National des Sciences Appliquees
Centre Informatique du 1er Cycle  Bat 110
20 Avenue A.Einstein
69621 Villeurbanne Cedex France
--------------------------------------------------------
Phone: 72 43 83 80 -   la premiere erreur c'est
Fax  : 72 43 85 33 -   de se lever le matin  ... GASTON
-------------------------------------------------------