home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / mac / programm / 20235 < prev    next >
Encoding:
Internet Message Format  |  1992-12-23  |  2.4 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!malgudi.oar.net!hyperion!desire.wright.edu!jmatthews
  2. From: jmatthews@desire.wright.edu
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Reading Resources II
  5. Message-ID: <1992Dec23.005321.6341@desire.wright.edu>
  6. Date: 23 Dec 92 00:53:21 EST
  7. References: <1992Dec22.190758.18473@dartvax.dartmouth.edu>
  8. Organization:  Wright State University 
  9. Lines: 55
  10.  
  11. In article <1992Dec22.190758.18473@dartvax.dartmouth.edu>, smsilver@coos.dartmouth.edu (Scott M. Silver) writes:
  12. > I am trying to make my own simple resource and read it in (correctly).
  13. > The resource is simply created by typing in the ascii region when
  14. > creating a new resource.  The following code works for printing out
  15. > the resource, but it really doesn't properly assign the correct
  16. > characters to the variable ch.
  17. > {PrintString: Res is handle to the resource. Size is the size of the
  18. > resource}
  19. > {Takes a handle to a resource and prints it out to the text window in
  20. > THINK Pascal}
  21. >
  22. >  procedure PrintString (res: Handle; size: integer);
  23. >   var
  24. >    index: integer;
  25. >    ch: char;
  26. >    scratch: Ptr;
  27. >  begin
  28. >   Hlock(res);
  29. >   for index := 0 to size - 1 do
  30. >    begin
  31. >     Scratch := Ptr(LongInt(Res^) + longint(index) - longint(1));
  32. >     BlockMove(Scratch, @ch, 2);
  33. >     write(ch);
  34. >     if index mod 32 = 0 then
  35. >      writeln;
  36. >    end;
  37. >   HUnlock(res);
  38. >  end;
  39. > This as it says justs prints out the resource to the text window in
  40. > Think Pascal.  I think my problem is a conceptual one having to do
  41. > with memory and not Resources.  Any help would be appreciated, and
  42. > thank you in advance.  
  43.  
  44. THINK Pascal's char data type is two bytes with the character code in
  45. the high byte (I think:-). Your resource is in effect a packed array of
  46. char. The CharsHandle data type (IM I-384) is just what you need. Try:
  47.  
  48.   for index:= 0 to size - 1 do
  49.     begin
  50.       write(CharsHandle(res)^^[index]);
  51.       if index mod 32 = 0 then writeln;
  52.     end;
  53.  
  54. BTW, I'm guessing this code is just for debugging. If you really need
  55. to print out char after char (using write or DrawChar), build a buffer
  56. of chars (say, your page width long) and use writeln or DrawString.
  57.  
  58. o----------------------------------------------------------------------------o
  59. | John B. Matthews, jmatthews@desire.wright.edu, disclaimer:= myViews <> WSU |
  60. |      "Whom the gods would destroy, they first invite to program in C"      |
  61. o----------------------------------------------------------------------------o
  62.