t79_strfield.pas 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. program t79_strfield;
  2. { t79 -- a STRING field written through a DI-addressed record element.
  3. CALC.INC:162, immediately after the set:
  4. Contents := '';
  5. Contents is String[70]. Within `with Sheet[I,J] do' the record's address
  6. is in DI, so the counted-string copy has to store <len><chars> through it,
  7. truncated to the field's capacity. Also covers a string VARIABLE source
  8. (strstore with DI as the destination), a plain record field (symbol+off),
  9. and the neighbour N to prove the copy stops at the field.
  10. A short literal must set the length to the SOURCE length, not the capacity:
  11. storing the capacity would print the bytes that happen to follow the
  12. literal. }
  13. type
  14. Cell = record
  15. S : string[5];
  16. N : integer;
  17. end;
  18. var
  19. r : Cell;
  20. g : array [1..2, 1..3] of Cell;
  21. i, j : integer;
  22. t : string[10];
  23. begin
  24. with r do
  25. begin
  26. S := 'abc';
  27. N := 4
  28. end;
  29. writeln (r.S);
  30. i := 2;
  31. j := 3;
  32. with g[i,j] do
  33. begin
  34. S := 'xy';
  35. N := 9
  36. end;
  37. writeln (g[2,3].S);
  38. with g[i,j] do
  39. writeln (S); (* the write arm, address in DI *)
  40. t := 'hello';
  41. with r do
  42. S := t;
  43. writeln (r.S);
  44. with r do
  45. S := 'abcdefgh';
  46. writeln (r.S);
  47. writeln (r.N)
  48. end.