objpas.pp 7.4 KB

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