tw28279.pp 982 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. {$mode objfpc}
  2. program Project1;
  3. var
  4. value_para_must_be_empty: boolean;
  5. procedure Foo1(a: AnsiString; out b: AnsiString);
  6. begin
  7. WriteLn(length(a)); WriteLn(length(b));
  8. if value_para_must_be_empty and
  9. (a<>'') then
  10. halt(2);
  11. if b<>'' then
  12. halt(3);
  13. b := 'a';
  14. end;
  15. procedure Foo2(out a: AnsiString; b: AnsiString);
  16. begin
  17. WriteLn(length(a)); WriteLn(length(b));
  18. if a<>'' then
  19. halt(4);
  20. if value_para_must_be_empty and
  21. (b<>'') then
  22. halt(5);
  23. b := 'a';
  24. end;
  25. var s1: AnsiString;
  26. function f: ansistring;
  27. begin
  28. { the s1 parameter must be finalised first to prevent accidental use of
  29. the finalised value }
  30. if s1<>'' then
  31. halt(1);
  32. f:='a';
  33. f:=f+'b';
  34. end;
  35. const x: AnsiString = 'abcde';
  36. begin
  37. value_para_must_be_empty:=true;
  38. s1 := copy(x,2,3)+'x';
  39. Foo1(s1,s1);
  40. s1 := copy(x,2,3)+'x';
  41. Foo2(s1,s1);
  42. value_para_must_be_empty:=false;
  43. s1 := copy(x,2,3)+'x';
  44. Foo1(f,s1);
  45. s1 := copy(x,2,3)+'x';
  46. Foo2(s1,f);
  47. end.