home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!malgudi.oar.net!hyperion!desire.wright.edu!jmatthews
- From: jmatthews@desire.wright.edu
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: Reading Resources II
- Message-ID: <1992Dec23.005321.6341@desire.wright.edu>
- Date: 23 Dec 92 00:53:21 EST
- References: <1992Dec22.190758.18473@dartvax.dartmouth.edu>
- Organization: Wright State University
- Lines: 55
-
- In article <1992Dec22.190758.18473@dartvax.dartmouth.edu>, smsilver@coos.dartmouth.edu (Scott M. Silver) writes:
- > I am trying to make my own simple resource and read it in (correctly).
- > The resource is simply created by typing in the ascii region when
- > creating a new resource. The following code works for printing out
- > the resource, but it really doesn't properly assign the correct
- > characters to the variable ch.
- >
- > {PrintString: Res is handle to the resource. Size is the size of the
- > resource}
- > {Takes a handle to a resource and prints it out to the text window in
- > THINK Pascal}
- >
- > procedure PrintString (res: Handle; size: integer);
- >
- > var
- > index: integer;
- > ch: char;
- > scratch: Ptr;
- >
- > begin
- > Hlock(res);
- > for index := 0 to size - 1 do
- > begin
- > Scratch := Ptr(LongInt(Res^) + longint(index) - longint(1));
- > BlockMove(Scratch, @ch, 2);
- > write(ch);
- > if index mod 32 = 0 then
- > writeln;
- > end;
- > HUnlock(res);
- > end;
- >
- > This as it says justs prints out the resource to the text window in
- > Think Pascal. I think my problem is a conceptual one having to do
- > with memory and not Resources. Any help would be appreciated, and
- > thank you in advance.
-
- THINK Pascal's char data type is two bytes with the character code in
- the high byte (I think:-). Your resource is in effect a packed array of
- char. The CharsHandle data type (IM I-384) is just what you need. Try:
-
- for index:= 0 to size - 1 do
- begin
- write(CharsHandle(res)^^[index]);
- if index mod 32 = 0 then writeln;
- end;
-
- BTW, I'm guessing this code is just for debugging. If you really need
- to print out char after char (using write or DrawChar), build a buffer
- of chars (say, your page width long) and use writeln or DrawString.
-
- o----------------------------------------------------------------------------o
- | John B. Matthews, jmatthews@desire.wright.edu, disclaimer:= myViews <> WSU |
- | "Whom the gods would destroy, they first invite to program in C" |
- o----------------------------------------------------------------------------o
-