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

const
   maxmsgsiz = 100;

type
   msgtyp = packed array [1..maxmsgsiz] of char;
   msgrectyp = packed record
                  id : [key(0,duplicates),aligned(2)] integer;
                  msg : msgtyp;
               end;
   msgfiltyp = file of msgrectyp;

var
   db : msgfiltyp; (* has to be global *)
   msg : msgrectyp;

begin
   (* open database *)
   open(db, 'msgs.isq', old, organization := indexed, access_method := keyed);
   (* write message to database *)
   msg.id := 1;
   msg.msg := 'Hi from Pascal!';
   db^ := msg;
   put(db);
   (* dump all messages in database *)
   resetk(db, 0);
   while not eof(db) do begin
      msg := db^;
      writeln('|' + msg.msg + '|');
      get(db);
   end;
   (* close database *)
   close(db);
end.
