program DateDec;
uses PXEngine, WinCrt;

const TableName = 'Table';

var   PxErr: Integer;
      TblHandle: TableHandle;
      FldHandle: FieldHandle;
      RecHandle: RecordHandle;
      Month, Day, Year: Integer;
      Date: longint;

procedure PX(Code : integer);
begin
  writeln(PXErrMsg(Code));
end;

begin
  PX(PXWinInit('MyApp', pxShared));
  PX(PXTblOpen(TableName, TblHandle, 0, False));
  PX(PXRecBufOpen(TblHandle, RecHandle));
  PX(PXFldHandle(TblHandle, 'Date Field', FldHandle));
  PX(PXRecGet(TblHandle, RecHandle));
  PX(PXGetDate(RecHandle, FldHandle, Date));

  (* Decode the date that was just retrieved. *)
  PxErr := PXDateDecode(date, Month, Day, Year);
  if PxErr <> PxSuccess then
    Writeln(PxErrMsg(PxErr))
  else Writeln('Month: ', Month, '   Day: ', Day, '   Year: ', Year);

  PX(PXRecBufClose(RecHandle));
  PX(PXTblClose(TblHandle));
  PX(PXExit);
end.
