[futurebasic] Re: Adding to Resource and Data forks

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 1998 : Group Archive : Group : All Groups

From: Charlie Dickman <charlied@...>
Date: Sun, 18 Jan 1998 12:57:07 -0500
MAWRPh <MAWRPh@...> wrote...

>I am working on a program that stores records in the data fork and text from
>an edit field in the resource fork. I am having two problems.
>
>1) I am leaving the file open (OPEN "R", #1 etc...) as long as the program is
>open. I do not OPEN, get data and then CLOSE after filling the record. On
>occasion when the computer has crashed (due to other activity, not necessarily
>my program) the data fork has been corrupted. Should I OPEN/CLOSE each time I
>access the file for data? I thought recent discussion here indicated that
>leaving the file OPEN was Ok.

I think the problem has to do with the fact that the OS buffers your file
and doesn't write all of the data to it until you close it. When your
machine crashes the file has not been properly terminated. This is the
stuff that trashes hard drives! You probably have some residual data from a
previously trashed file tacked onto your file or, worse, your file is cross
linked to another supposedly "good" file which is no longer usable. It's
similar to what might happen if the power goes out during any file update
operation. Close the file and you'll get it cleaned up nicely. You can then
reopen it when you need to read or update it.


>2) This is not a PG project but I am using FN
>pGreplaceRes(resHndl&,resTp&,resID,resName$) modified to use an external
>resource file(FN pGreplaceXRes and FN pGreplaceRes combined) to get a ZTXT
>handle and save it as a resource. I call FN pGreplaceRes like this:
>
>      GET FIELD efHndl&, _efNum
>      FN pGreplaceRes(efHndl&, _"XXXX", resNum%, title$, gCurResFile%)
>      KILL FIELD efHndl&
>
>This seems to work fine when saving changes to the edit field but when I save
>it the first time (a resource of the type _"XXXX" exists but not one with a
>number of resNum%) I get strange things. Usually the edit field is refreshed
>with garbage which also is saved to the resource specified. Occasionally I
>have had menus in the menu bar affected. The only changes I made to FN
>pGreplaceRes was to add the calls to FN CURRESFILE and CALL USERESFILE. These
>errors have only occurred on my PPC 8500, not my IIci.
>

I use pGreplaceRes just as you do and don't have any problems but I think
the resource has to exist before you can replace it. The following snippet
is from one of my programs' initialization logic. It ensures that a
resource of the proper type exists and then I can pGreplaceRes it at will.

  gBourH& = FN GETRESOURCE(_"Boré", 128)
  LONG IF gBourH& = 0
    gBourH& = FN NEWHANDLE _clear (_gBour)
    BLOCKMOVE @gBour, [gBourH&], _gBour
    CALL ADDRESOURCE(gBourH&, _"Boré", 128, "")
  XELSE
    BLOCKMOVE [gBourH&], @gBour, _gBour
  END IF

Charlie Dickman
charlied@...