(* Collection of code snippets by Arne Vajhøj *)
(* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) *)
program p2(input,output);

const
   blocksize = 8192;
   blocks = 10;
   memsiz = blocks * blocksize;
   maxmsgsiz = 100;
   maxmsgs = memsiz div maxmsgsiz;

type
   msgtype = packed array [1..maxmsgsiz] of char;
   memtype = record
                   case boolean of
                      true : ( dummy : packed array [1..memsiz] of char; );
                      false : ( msg : packed array [1..maxmsgs] of msgtype; );
                end;

var
   mem : [common(msgpsect)] memtype;
   i, msglen : integer;

begin
   (* write to shareable image *)   
   i := 1;
   while mem.msg[i][1] <> chr(0) do i := i + 1;
   mem.msg[i] := 'Hi from Pascal!' + chr(0);
   (* dump shareable image *)
   for i := 1 to maxmsgs do begin
      if mem.msg[i][1] <> chr(0) then begin
         msglen := index(mem.msg[i], chr(0));
         writeln('|' + substr(mem.msg[i], 1, msglen) + '|');
      end;
   end;
end.
