tconstref3.pp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. program tconstref3;
  2. {$mode objfpc}{$h+}
  3. uses
  4. SysUtils;
  5. const
  6. CGuid: TGuid = '{67BD8D43-8960-491C-AA3A-50EC74A02F36}';
  7. type
  8. PSmallRecord = ^TSmallRecord;
  9. TSmallRecord = record
  10. p: PtrInt;
  11. end;
  12. PAclass = ^TAclass;
  13. TAclass = class
  14. public
  15. p: PtrInt;
  16. end;
  17. procedure TestConstRefIntegerAlias(AParam: PInteger); [external name '_TESTCONSTREFINTEGER'];
  18. procedure TestConstRefInteger(constref AParam: integer); [public, alias: '_TESTCONSTREFINTEGER'];
  19. begin
  20. if AParam<>$1234567 then
  21. halt(1);
  22. end;
  23. procedure TestConstRefStringAlias(AParam: PString); [external name '_TESTCONSTREFSTRING'];
  24. procedure TestConstRefString(constref AParam: String); [public, alias: '_TESTCONSTREFSTRING'];
  25. begin
  26. if AParam<>'1234567' then
  27. halt(1);
  28. end;
  29. procedure TestConstRefGUIDAlias(AParam: PGuid); [external name '_TESTCONSTREFGUID'];
  30. procedure TestConstRefGUID(constref AParam: TGuid); [public, alias: '_TESTCONSTREFGUID'];
  31. begin
  32. if GUIDToString(AParam)<>'{67BD8D43-8960-491C-AA3A-50EC74A02F36}' then
  33. halt(1);
  34. end;
  35. procedure TestConstRefRecordAlias(AParam: PSmallRecord); [external name '_TESTCONSTREFRECORD'];
  36. procedure TestConstRefRecord(constref AParam: TSmallRecord); [public, alias: '_TESTCONSTREFRECORD'];
  37. begin
  38. if AParam.p<>$7654321 then
  39. halt(1);
  40. end;
  41. procedure TestConstRefClassAlias(AParam: PAClass); [external name '_TESTCONSTREFCLASS'];
  42. procedure TestConstRefClass(constref AParam: TAClass); [public, alias: '_TESTCONSTREFCLASS'];
  43. begin
  44. if AParam.p<>$3456789 then
  45. halt(1);
  46. end;
  47. var a: integer;
  48. s: string;
  49. p: tguid;
  50. sr: TSmallRecord;
  51. ac: TAclass;
  52. begin
  53. a := $1234567;
  54. TestConstRefIntegerAlias(@a);
  55. s := '1234567';
  56. TestConstRefStringAlias(@s);
  57. p := CGuid;
  58. TestConstRefGUIDAlias(@p);
  59. sr.p:=$7654321;
  60. TestConstRefRecordAlias(@sr);
  61. ac := TAclass.Create;
  62. ac.p := $3456789;
  63. TestConstRefClassAlias(@ac);
  64. ac.Free;
  65. end.