toperator94.pp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. program toperator94;
  2. {$mode objfpc}
  3. {$modeswitch advancedrecords}
  4. type
  5. TString80 = String[80];
  6. TString90 = String[90];
  7. TString40 = String[40];
  8. TString100 = String[100];
  9. TTest1 = record
  10. class operator :=(const aArg: TTest1): TString80;
  11. end;
  12. TTest2 = record
  13. class operator :=(const aArg: TTest2): ShortString;
  14. end;
  15. var
  16. ImplicitTest1ShortString: LongInt;
  17. ImplicitTest1String80: LongInt;
  18. ImplicitTest2ShortString: LongInt;
  19. ImplicitTest2String80: LongInt;
  20. class operator TTest1.:=(const aArg: TTest1): TString80;
  21. begin
  22. Writeln('TTest1 Implicit TString80');
  23. Inc(ImplicitTest1String80);
  24. Result := '';
  25. end;
  26. class operator TTest2.:=(const aArg: TTest2): ShortString;
  27. begin
  28. Writeln('TTest2 Implicit ShortString');
  29. Inc(ImplicitTest2ShortString);
  30. Result := '';
  31. end;
  32. operator :=(const aArg: TTest1): ShortString;
  33. begin
  34. Writeln('TTest1 Implicit ShortString');
  35. Inc(ImplicitTest1ShortString);
  36. Result := '';
  37. end;
  38. operator :=(const aArg: TTest2): TString80;
  39. begin
  40. Writeln('TTest2 Implicit TString80');
  41. Inc(ImplicitTest2String80);
  42. Result := '';
  43. end;
  44. var
  45. t1: TTest1;
  46. t2: TTest2;
  47. s80: TString80;
  48. begin
  49. s80 := t1;
  50. if ImplicitTest1ShortString <> 1 then
  51. Halt(1);
  52. s80 := t2;
  53. if ImplicitTest2ShortString <> 1 then
  54. Halt(2);
  55. Writeln('ok');
  56. end.