openlib.pas 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. {
  2. Two ways of opening and using libraries
  3. Free Pascal for MorphOS example
  4. Copyright (C) 2004 by Karoly Balogh
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. { * 2004.12.10 * }
  12. program openlib;
  13. uses exec, intuition, graphics, utility;
  14. { * You can enable this to manually open needed libraries, * }
  15. { * else it will use functions built into the units; * }
  16. { * _DO NOT_ open/close DOS and Utility libraries manually * }
  17. { * since that's handled by the default startup/shutdown code. * }
  18. { DEFINE USEOPENLIB}
  19. const
  20. ERRMSG_NOINTUI = 'Unable to open intuition.library V50!';
  21. ERRMSG_NOGFX = 'Unable to open graphics.library V50!';
  22. const
  23. MSG_INTUIOK = 'intuition.library V50 opened successfully.';
  24. MSG_GFXOK = 'graphics.library V50 opened successfully.';
  25. procedure ShutDown(exitString: String; code: LongInt);
  26. begin
  27. { * When using opening functions built into the units, * }
  28. { * it's not needed to close libs manually, since unit exit *}
  29. { * code will do it for you. * }
  30. {$IFDEF USEOPENLIB}
  31. if assigned(intuitionBase) then CloseLibrary(PLibrary(intuitionBase));
  32. if assigned(gfxBase) then CloseLibrary(gfxBase);
  33. {$ENDIF}
  34. if exitString<>'' then writeln(exitString);
  35. Halt(code);
  36. end;
  37. procedure Init;
  38. begin
  39. { * Using built-in or custom library opening functions. * }
  40. { * It's recommended not to mix up the two ways. * }
  41. { * It's not needed to implement both of them in your * }
  42. { * programs, it's just an example to show it. * }
  43. {$IFDEF USEOPENLIB}
  44. IntuitionBase:=OpenLibrary(INTUITIONNAME,50);
  45. if IntuitionBase=NIL then
  46. ShutDown(ERRMSG_NOINTUI,20)
  47. else
  48. writeln(MSG_INTUIOK);
  49. GfxBase:=OpenLibrary(GRAPHICSNAME,50);
  50. if GfxBase=NIL then
  51. ShutDown(ERRMSG_NOGFX,20)
  52. else
  53. writeln(MSG_GFXOK);
  54. {$ELSE}
  55. if Not InitIntuitionLibrary then
  56. ShutDown(ERRMSG_NOINTUI,20)
  57. else
  58. writeln(MSG_INTUIOK);
  59. if Not InitGraphicsLibrary then
  60. ShutDown(ERRMSG_NOGFX,20)
  61. else
  62. writeln(MSG_GFXOK);
  63. {$ENDIF}
  64. end;
  65. begin
  66. Init;
  67. ShutDown('',0);
  68. end.