openlib.pas 2.4 KB

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