[comp.sys.mac.programmer] Problems in completely changing a resource :

vrm@blackwater.cerc.wvu.wvnet.edu (Vasile R. Montan) (05/07/91)

The usual way to change the contents of a resource are to load it into
memory, make the changes you want in the resource, and then set the
ChangedResource flag so that the modified resource will be written
out to disk when the file closes.

In my case, however, I am trying to do something a little different.  I
have a handle to a variable length array.  There is a resource on the disk,
and I want to completely replace the contents of that resource with
the array which my handle indirectly points to.  The strategy which I'm
trying (and this *ought* to work, but it doesn't seem to be!) is to
remove the resource from the file completely, and then to add a new
resource of the same number.  My code looks like this (I have left out
all of my error checking for clarity, or this code would be much longer):

{Open the file}
    FileNumber := OpenResFile(RoomFName);

{Remove the old resource}
    TempHandle := GetResource('ROOM', RoomNum);
    RmveResource(TempHandle);
    DisposHandle(TempHandle);  {Not ReleaseResource, because we removed it}
    UpdateResFile(FileNumber);

{Add the new resource}
    AddResource(Handle(Room), 'ROOM', RoomNum, RoomName);
    UpdateResFile(FileNumber);

{Clean up and close}
    ReleaseResource(Handle(Room));
    CloseResFile(FileNumber);

Can you think of any reason why this shouldn't work?  Is there something
one of these calls does that I don't know about?  (To make matters worse,
my surrounding code is very complicated and it's difficult to pin down
where the problem is happening, or even what the problem is exactly,
because things just start going haywire.  To make matters worse still,
this code works beautifully when I am running it in the Lightspeed Pascal 
programming environment; the problem only occurs when I compile
the program as a stand-alone application.  Don't you hate that kind
of problem?)

Thank you for your help.

--Kurisuto
un020070@vaxa.wvnet.edu
Please respond by email if possible; I seem to be having problems with the
news today as well. :-(