objpas.pp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1998,99 by the Free Pascal development team
  5. This unit makes Free Pascal as much as possible Delphi compatible
  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. {$Mode ObjFpc}
  13. {$I-,S-}
  14. unit objpas;
  15. interface
  16. type
  17. { first, in object pascal, the types must be redefined }
  18. smallint = system.integer;
  19. integer = system.longint;
  20. { the compiler searches in the objpas unit for the tvarrec symbol }
  21. TVarRec = System.TVarRec;
  22. PVarRec = ^TVarRec;
  23. {****************************************************************************
  24. Compatibility routines.
  25. ****************************************************************************}
  26. { Untyped file support }
  27. Procedure AssignFile(Var f:File;const Name:string);
  28. Procedure AssignFile(Var f:File;p:pchar);
  29. Procedure AssignFile(Var f:File;c:char);
  30. Procedure CloseFile(Var f:File);
  31. { Text file support }
  32. Procedure AssignFile(Var t:Text;const s:string);
  33. Procedure AssignFile(Var t:Text;p:pchar);
  34. Procedure AssignFile(Var t:Text;c:char);
  35. Procedure CloseFile(Var t:Text);
  36. { Typed file supoort }
  37. Procedure AssignFile(Var f:TypedFile;const Name:string);
  38. Procedure AssignFile(Var f:TypedFile;p:pchar);
  39. Procedure AssignFile(Var f:TypedFile;c:char);
  40. { ParamStr should return also an ansistring }
  41. Function ParamStr(Param : Integer) : Ansistring;
  42. {$ifdef HasResourceStrings}
  43. { Resourcestring support }
  44. Function GetResourceString(Hash : Longint) : AnsiString;
  45. Procedure ResetResourceTables;
  46. Function SetResourceString(Hash : longint; Const Value : AnsiString) : Boolean;
  47. {$endif}
  48. implementation
  49. {****************************************************************************
  50. Compatibility routines.
  51. ****************************************************************************}
  52. { Untyped file support }
  53. Procedure AssignFile(Var f:File;const Name:string);
  54. begin
  55. System.Assign (F,Name);
  56. end;
  57. Procedure AssignFile(Var f:File;p:pchar);
  58. begin
  59. System.Assign (F,P);
  60. end;
  61. Procedure AssignFile(Var f:File;c:char);
  62. begin
  63. System.Assign (F,C);
  64. end;
  65. Procedure CloseFile(Var f:File);
  66. begin
  67. System.Close(f);
  68. end;
  69. { Text file support }
  70. Procedure AssignFile(Var t:Text;const s:string);
  71. begin
  72. System.Assign (T,S);
  73. end;
  74. Procedure AssignFile(Var t:Text;p:pchar);
  75. begin
  76. System.Assign (T,P);
  77. end;
  78. Procedure AssignFile(Var t:Text;c:char);
  79. begin
  80. System.Assign (T,C);
  81. end;
  82. Procedure CloseFile(Var t:Text);
  83. begin
  84. Close(T);
  85. end;
  86. { Typed file supoort }
  87. Procedure AssignFile(Var f:TypedFile;const Name:string);
  88. begin
  89. system.Assign(F,Name);
  90. end;
  91. Procedure AssignFile(Var f:TypedFile;p:pchar);
  92. begin
  93. system.Assign (F,p);
  94. end;
  95. Procedure AssignFile(Var f:TypedFile;c:char);
  96. begin
  97. system.Assign (F,C);
  98. end;
  99. Function ParamStr(Param : Integer) : Ansistring;
  100. Var Len : longint;
  101. begin
  102. if (Param>=0) and (Param<argc) then
  103. begin
  104. Len:=0;
  105. While Argv[Param][Len]<>#0 do
  106. Inc(len);
  107. SetLength(Result,Len);
  108. If Len>0 then
  109. Move(Argv[Param][0],Result[1],Len);
  110. end
  111. else
  112. paramstr:='';
  113. end;
  114. {$IFDEF HasResourceStrings}
  115. { ---------------------------------------------------------------------
  116. ResourceString support
  117. ---------------------------------------------------------------------}
  118. Type
  119. TResourceStringRecord = Packed Record
  120. DefaultValue,
  121. CurrentValue : AnsiString;
  122. HashValue : longint;
  123. end;
  124. TResourceStringTable = Packed Record
  125. Count : longint;
  126. Resrec : Array[Word] of TResourceStringRecord;
  127. end;
  128. Var
  129. ResourceStringTable : TResourceStringTable; External Name 'RESOURCESTRINGLIST';
  130. Function FindHashIndex (Value : Longint) : Longint;
  131. Var
  132. I : longint;
  133. begin
  134. // Linear search, later we can implement binary search.
  135. With ResourceStringTable do
  136. For I:=0 to Count-1 do
  137. If Value=Resrec[I].HashValue then
  138. begin
  139. Result:=I;
  140. exit;
  141. end;
  142. Result:=-1;
  143. end;
  144. Function GetResourceString(Hash : Longint) : AnsiString;[Public,Alias : 'FPC_GETRESOURCESTRING'];
  145. begin
  146. Hash:=FindHashIndex(Hash);
  147. If Hash<>-1 then
  148. Result:=ResourceStringTable.ResRec[Hash].CurrentValue
  149. else
  150. Result:='';
  151. end;
  152. Function SetResourceString(Hash : longint; Const Value : AnsiString) : Boolean;
  153. begin
  154. Hash:=FindHashIndex(Hash);
  155. Result:=Hash<>-1;
  156. If Result then
  157. ResourceStringTable.ResRec[Hash].CurrentValue:=Value;
  158. end;
  159. Procedure ResetResourceTables;
  160. Var I : longint;
  161. begin
  162. With ResourceStringTable do
  163. For I:=0 to Count-1 do
  164. With ResRec[i] do
  165. CurrentValue:=DefaultValue;
  166. end;
  167. Initialization
  168. ResetResourceTables;
  169. {$endif}
  170. end.
  171. {
  172. $Log$
  173. Revision 1.29 1999-07-23 23:13:54 peter
  174. * array[cardinal] is buggy, use array[word]
  175. * small fix in getresourcestring
  176. Revision 1.28 1999/07/23 22:51:11 michael
  177. * Added HasResourceStrings check
  178. Revision 1.27 1999/07/22 20:30:13 michael
  179. + Implemented resource stuff
  180. Revision 1.26 1999/07/07 10:04:04 michael
  181. + Paramstr now returns cmdline args >255 chars in ansistring objpas.pp
  182. Revision 1.25 1999/07/06 22:44:22 florian
  183. + implemented a paramstr function which returns an ansistring, nevertheless
  184. it is limited to 255 chars because it maps to the system.paramstr, maybe
  185. we should use cmdline instead
  186. Revision 1.24 1999/05/17 21:52:43 florian
  187. * most of the Object Pascal stuff moved to the system unit
  188. Revision 1.23 1999/05/13 21:54:28 peter
  189. * objpas fixes
  190. Revision 1.22 1999/04/16 20:47:20 florian
  191. + tobject.messagestringtable function for Megido/GTK support
  192. added
  193. Revision 1.21 1999/02/23 14:04:36 pierre
  194. * call %edi => call *%edi
  195. Revision 1.20 1999/02/22 23:30:54 florian
  196. + TObject.Dispatch and TObject.DispatchStr added, working
  197. Revision 1.19 1998/12/24 10:12:03 michael
  198. Implemented AssignFile and CloseFile compatibility
  199. Revision 1.18 1998/10/12 12:42:58 florian
  200. * as operator runtime error can be now caught by an errorproc
  201. Revision 1.17 1998/10/05 12:32:53 peter
  202. + assert() support
  203. Revision 1.16 1998/10/03 15:07:16 florian
  204. + TObject.AfterConstruction and TObject.BeforeDestruction of Delphi 4
  205. Revision 1.15 1998/09/24 16:13:48 michael
  206. Changes in exception and open array handling
  207. Revision 1.14 1998/09/23 12:40:43 michael
  208. Fixed TVarRec again. Should be OK now
  209. Revision 1.13 1998/09/23 12:18:32 michael
  210. + added VType in TVArRec
  211. Revision 1.12 1998/09/23 10:00:47 peter
  212. * tvarrec should be 8 bytes
  213. Revision 1.11 1998/09/22 15:30:07 peter
  214. * array of const update
  215. Revision 1.9 1998/09/16 13:08:19 michael
  216. Added AbstractErrorHandler
  217. Revision 1.8 1998/09/06 21:27:31 florian
  218. + method tobject.classinfo added
  219. Revision 1.7 1998/09/04 08:49:06 peter
  220. * 0.99.5 doesn't compile a whole objpas anymore to overcome crashes
  221. Revision 1.6 1998/08/23 20:58:52 florian
  222. + rtti for objects and classes
  223. + TObject.GetClassName implemented
  224. Revision 1.5 1998/07/30 16:10:11 michael
  225. + Added support for ExceptProc+
  226. Revision 1.4 1998/07/29 15:44:33 michael
  227. included sysutils and math.pp as target. They compile now.
  228. Revision 1.3 1998/07/29 10:09:28 michael
  229. + put in exception support
  230. Revision 1.2 1998/03/25 23:40:24 florian
  231. + stuff from old objpash.inc and objpas.inc merged in
  232. }