{ Testing the wParamApplic2.pp unit.
  Test also the wUtiles0.pp unit, some functions.
  Short test.
  --------------------------------------------}
program tEx025;

// To tell FreePascal that the application is a Graphical User Interface
// i.e. is running in windows, not in text mode.
{$APPTYPE GUI}

Uses
  Windows
 ,wGlobals2
 ,wMessages2
 ,wUtiles0
 ,wApplication0
 ,wParamApplic2
 ,wWindow0
 ,wErrors0
 ,wDebug0;

type
  PMyWindow = ^TMyWindow;
  TMyWindow = object(TWindow)
  //"""""""""""""""""""""""""
  constructor Init(strWinTitlePrm:ShortString);
  procedure WMPaint;
  procedure WMButtonDown;
  function WindowProc(hWindow:HWND; wMsg:UINT; wPar:WPARAM; lPar:LPARAM):LRESULT; virtual;
  end; // TMyWindow = object(TWindow0)

// var nNotUsed : integer; // only to avoid an error message while compliling in DevPascal 1.9

constructor TMyWindow.Init(strWinTitlePrm:ShortString);
//=====================================================
begin
inherited Init(strWinTitlePrm);
end;  // TMyWindow.Init

procedure TMyWindow.WMPaint;
//==========================
Var
  rRec        : rect;
  dc          : hdc;
  ps          : paintstruct;

begin
dc:=BeginPaint(hWin, @ps);
GetClientRect(hWin, @rRec);
DrawText( dc, 'Example 025 Testing the wParamApplic2.pp unit.',-1,@rRec,
          DT_SINGLELINE or DT_CENTER or DT_VCENTER);
rRec.Top :=rRec.top    + 50;
DrawText( dc, 'Click with the mouse',-1,@rRec,
          DT_SINGLELINE or DT_CENTER or DT_VCENTER);
EndPaint(hWin, ps);
end;  // TMyWindow.WMPaint

procedure TMyWindow.WMButtonDown;
//===============================
var
  strName,
  strParam,
  strS        : ShortString;
  nn,
  nEnd        : integer; // to test the GetIntValue function. (in wUtiles0.pp)
  nVal1,                 // idem
  nVal2,
  nVal3,
  nVal4,
  nVal5
              : int32;

begin
DBW0(1, 'Directory           = ' + gglpoPrm^.strEXEDir);
DBW0(1, 'Name                = ' + gglpoPrm^.strEXEName);
DBW0(1, 'Extension           = ' + gglpoPrm^.strEXEExt);

DBW0(1, 'strParamPath        = ' + gglpoPrm^.strParamPath);
DBW0(1, 'gglstrMsgPathName   = ' + gglstrMsgPathName);
DBW0(1, 'gglstrErrorPathName = ' + gglstrErrorPathName);
DBW0(1, 'gglstrDebugPathName = ' + gglstrDebugPathName);
DBW0(1, '------------------------');

strS:='ParamPath =*1*2.prm  ';
DBW0(2, ' ');
DBW0(2, 'the string : "' + strS + '"');
DBW0(2, 'becomes before and after interpretation');
gglpoPrm^.GetNameParam(strS, strName, strParam);
DBW0(2, 'Identificator = "' + strName + '"');
DBW0(2, 'Parameter     = "' + strParam + '"');
DBW0(2, 'Interpreted   = "' + gglpoPrm^.Interpret(strParam) + '"');

strS:='  ErrorPath =  *1*2.err  // comments can follow';
DBW0(2, ' ');
DBW0(2, 'the string : "' + strS + '"');
DBW0(2, 'becomes before and after interpretation');
gglpoPrm^.GetNameParam(strS, strName, strParam);
DBW0(2, 'Identificator = "' + strName + '"');
DBW0(2, 'Parameter     = "' + strParam + '"');
DBW0(2, 'Interpreted   = "' + gglpoPrm^.Interpret(strParam) + '"');
DBW0(2, 'LTrimed       = "' +
        gglpoPrm^.LTrim(gglpoPrm^.Interpret(strParam)) + '"');

strS:='MsgPath =*1\*2.prm  // the  \  will be skipped';
DBW0(2, ' ');
DBW0(2, 'the string : "' + strS + '"');
DBW0(2, 'becomes before and after interpretation');
gglpoPrm^.GetNameParam(strS, strName, strParam);
DBW0(2, 'Identificator = "' + strName + '"');
DBW0(2, 'Parameter     = "' + strParam + '"');
DBW0(2, 'Interpreted   = "' + gglpoPrm^.Interpret(strParam) + '"');

// to test the GetIntValue
DBW0(4, ' ');
strS:='Noting 3, 56, 7489, -77 finished';
nVal1:=GetIntValue(   1, strS, nEnd);
nVal2:=GetIntValue(nEnd, strS, nEnd);
nVal3:=GetIntValue(nEnd, strS, nEnd);
nVal4:=GetIntValue(nEnd, strS, nEnd);
nVal5:=GetIntValue(nEnd, strS, nEnd);
DBW0(4, 'From the string : "' + strS);
DBW0(4, 'GetIntValue gets nEnd=' + IntToStr(nEnd,3) + ' and the values :');
DBW0(4, IntToStr(nVal1, 5) + IntToStr(nVal2, 5) + IntToStr(nVal3, 5) +
        IntToStr(nVal4, 5) + IntToStr(nVal5, 5));
DBW0(8, 'The last 0 and nEnd = 0 mean there was no more numbers following');
end;  // TMyWindow.WMButtonDown

function TMyWindow.WindowProc(hWindow:HWND; wMsg:UINT; wPar:WPARAM; lPar:LPARAM):LRESULT;
//=======================================================================================
// All window messages are send here.

Begin
WindowProc := 0; // Default return value when processing a message

Case wMsg Of
   WM_paint : WMPaint;
   WM_LButtonDown,
   WM_RButtonDown : WMButtonDown;

   else begin // Case wMsg Of
      // Default processing of the messages.
      WindowProc:=inherited WindowProc(hWindow, wMsg, wPar, lPar);
      end; // Case wMsg Of
   End; // Case wMsg Of

End;  // TMyWindow.WindowProc

var
  oApp        : TApplication;
  poMyMainWin : PMyWindow;

Begin // MAIN ******
// Name under which the main window is registered. Spaces are not allowed
oApp.Init('Example025');

// Creation of the main window
new(poMyMainWin, Init('tEx025. Test the wParamApplic2.pp unit.'));

oApp.Run;
oApp.Done;  // The main window object is disposed here.
End.

