unit wErrors2;

{  Feel free to use this unit as you want.
   First developped by Bernard Gisin

   This unit is a continuation of the unit  wErrors0.pp,
   But is independent of window.
   Uses wErrors0, wGlobals2, wMessages2, wVariableNumLink2
   To write error information in the error window, but
   using text witten in the message file  '.msg'
-----------------------------------------------------}

INTERFACE
//"""""""

uses wGlobals2;

procedure ErrorWriteMsg(msgErrorNumber:word32);
//=============================================
{  This skips a line,
   write 'Error Nr=' lErrorNumber, strMsg, at time & date
   dwErrorNumber = a constant number defined in this unit.
   strMsg       = name of the unit . name of the method (=procedure)
                  & additionnal information
  ------------------------------------------------------------}

IMPLEMENTATION
//""""""""""""

uses  wVariableNumLink2, wMessages2, wErrors0, wDebug0;

var nUnused : integer; // to avoid error in DevPascal while compiling

procedure ErrorWriteMsg(msgErrorNumber:word32);
//=============================================
{  This skips a line,
   write 'Error Nr=' lErrorNumber, strMsg, at time & date
   lErrorNumber = a constant number defined in this unit.
   strMsg       = name of the unit . name of the method (=procedure)
                  & additionnal information
  ------------------------------------------------------------}
var
  strS        : ShortString;
  wSecurity   : word;

  // To memorise where we are in the message file
  // After displaying the error, which uses the message file,
  // go back to the same position in the message file
  // as the one at the entrence of this procedure.
  ptr         : pointer;
  wError,
  wPos        : word32;

begin
GetMsgPos(ptr, wPos); // memorise the position in the message file

// Write the first error line
strS:=GetMsg(msgErrorNumber);
strS:=Interpret(strS); // convert any information coded in variables if any

// Write the first line of the error message.
ErrorWrite(msgErrorNumber, strS);

// Gets all supplementary error lines, and write them
strS:=GetMsg(msgNext);
wSecurity:=0;

while (strS <> ctestrLineEND) // not an end of text messages
   and (gglwMessages2LastNum = 0) // the text comes from a line beginning with a '0'
                                  // This test avoid to have to end each error descriptions
                                  // with a '...END'
                                  // a number indicate the starting of a new
                                  // error message
   and (wSecurity < 100) do begin
   // transforme the variable content  @number
   // into strings. See wVariableNumLink2.pp
   strS:=Interpret(strS);

   ErrorComment(msgErrorNumber, strS); // write the error message

   strS:=GetMsg(msgNext); // get the next error message, or the end.
   inc(wSecurity);
   end;

// go back to the original position in the message file.
SetMsgPos(ptr, wPos, wError);  // ignore any error
end;  // ErrorWrite

end. // unit wErrors2;
