{uses
    Dos, Objects, Drivers, Memory, Views, Menus, Dialogs, StdDlg, MsgBox, App, ColorSel;
 }

uses
  Dos, Objects, Drivers, Memory, Views, Menus, Dialogs, StdDlg, HistList,
  MsgBox, App, DemoCmds, Gadgets, Puzzle, Calendar, AsciiTab, Calc,
  HelpFile, DemoHelp, ColorSel, MouseDlg, Editors;


type
    tdrawbuffer = array[0..maxviewwidth-1] of word;


    ptatusline = ^tatusline;
    tatusline = object(tstatusline)
              function hint(ahelpctx : word) : string; virtual;
    end;

    mapp = object(tapplication)
         procedure calculatorerror; virtual;
         procedure initmenubar; virtual;
         procedure newfile; virtual;
         procedure handleevent(var event : tevent); virtual;
         procedure verifyinvoice; virtual;
         procedure badfile; virtual;
         procedure initstatusline; virtual;
         procedure welcome; virtual;
         procedure colors; virtual;
         procedure getevent(var event : tevent); virtual;
         procedure openfile; virtual;
         procedure parents; virtual;
         procedure nation; virtual;
         procedure language; virtual;
         procedure savestu; virtual;
    end;


    predstatictext = ^redstatictext;
    redstatictext = object(tstatictext)
                  function getpalette: ppalette; virtual;
    end;

    information = record

                add1 : string[28];
                add2 : string[28];
                taxcity : string[4];
                taxstate : string[4];
                taxsales : string[4];
                name : string[18];
    end;

    stuff = record
          ilename : string[12];
    end;

    student_i = record
              first : string[10];
              mid : string[10];
              id : string[5];
              grade : string[2];
              teach : string[10];
              add : string[20];
              phone : string[11];
              city : string[10];
              state : string[2];
              zip : string[5];
              last : string[10];
    end;

    parents_i = record
              fat : string[20];
              fatno : string[11];
              mot : string[20];
              motno : string[11];
    end;

    nat_i = record
            nati : word;
    end;

    lag_i = record
          home : word;
          school : word;
    end;

    invoice = record
            studentfo : student_i;
            parentfo : parents_i;
            nationfo : nat_i;
            langfo : lag_i;
    end;

    idd = record
        nvoice : string[8];
    end;

    lookvar = record
            place : longint;
            compat : byte;
    end;

    prinfo = record
           what : word;
           where : word;
    end;

const
     maxlines = 100;
     cmnewfile = 200;
     cmopenfile = 201;
     cmprintfile = 202;
     cmnewinvoice = 203;
     cmfindinvoice = 204;
     cmviewvalues = 205;
     cmprofit = 206;
     cmcolors = 207;
     cmhelpwindow = 208;
     cmabout = 209;
     hcsnewinvoice = 1000;
     hcsopeninvoice = 1001;
     hcsprintinvoice = 1002;
     hcsnewv = 1003;
     hcsfindv = 1004;
     hcsviewval = 1005;
     hccalcvalue = 1006;
     hcfilemenu = 1007;
     hcinvoicemenu = 1008;
     hcnewfiledialog = 1009;
     hcaddress = 1010;
     hccity = 1011;
     hccitytax = 1012;
     hcstatetax = 1013;
     hcnochange = 1014;
     hccompanyname = 1015;
     hcentername = 1016;
     hcfindinvoice = 1017;
     hcenternumber = 1018;
     hcenterpaymethod = 1019;
     hcentersubtotal = 1020;
     hcentertaxcollected = 1021;
     hcenterproductcost = 1022;
     hcenternontaxable = 1023;
     hcenterdate = 1024;
     hcdestination = 1025;
     hctype = 1026;
     hcspecial = 1027;
     hcsexit = 1028;
     hcscolors = 1029;
     hcquickhelp = 1030;
     hcsabout = 1031;
     wincount: integer = 0;

var
   welcomenumber : boolean;
   waste : integer;
   fi : file;
   sizeinfo : word;
   tapp : mapp;
   info : information;
   f : stuff;
   tinvoice : student_i;
   parvar : parents_i;
   nat : nat_i;
   lag : lag_i;
   final,look : invoice;
   sizeinvoice : word;
   real1,real2,real3 : real;
   i : idd;
   printstuff : prinfo;
   mycommandset,printcommandset : tcommandset;
   linecount : integer;
   lines : array[0..maxlines-1] of pstring;
   lastid : longint;
   lookrec : array[0..9] of lookvar;
   looknum,compat : byte;

procedure tag(var fil : file);
begin
seek(fil,filesize(fil));
end;

function redstatictext.getpalette: ppalette;
const
  credstatictext = #0;
  predstatictext : string[length(credstatictext)] = credstatictext;
begin
  getpalette := @predstatictext;
end;

procedure mapp.welcome;
var
   r : trect;
   dialog : pdialog;
   control : word;
begin
     r.assign(20,3,48,16);
     dialog := new(pdialog,init(r,'Welcome!'));
     with dialog^ do
     begin
          r.assign(5,2,25,3);
          insert(new(pstatictext,init(r,'  StudenTrack 1.0')));
          r.assign(7,4,25,5);
          insert(new(pstatictext,init(r,'By Alan Marble')));
          r.assign(4,6,25,7);
          insert(new(pstatictext,init(r,'Created Feb. 19 1996')));
          r.assign(9,9,19,11);
          insert(new(pbutton,init(r,'~O~k',cmok,bfdefault)));

     end;
     control := desktop^.execview(dialog);
end;

procedure mapp.initmenubar;
var r : trect;
begin
     getextent(r);
     r.b.y := r.a.y + 1;
     menubar := new (pmenubar,init(r,newmenu(
       newsubmenu('~F~ile',hcfilemenu,newmenu(
         newitem('~N~ew record list','F4',kbf4,cmnewfile,hcsnewinvoice,
         newitem('~O~pen record list','F3',kbf3,cmopenfile,hcsopeninvoice,
         newline(
         newitem('~P~rint options','F2',kbf2,cmprintfile,hcsprintinvoice,
         newline(
         newitem('E~x~it','Alt+X',kbaltx,cmquit,hcsexit,
         nil))))))),
       newsubmenu('S~t~udent',hcinvoicemenu,newmenu(
         newitem('N~e~w student record','F7',kbf7,cmnewinvoice,hcsnewv,
         newitem('Fin~d~ student record','F5',kbf5,cmfindinvoice,hcsfindv,
         nil))),
       newsubmenu('~S~pecial',hcspecial,newmenu(
         newitem('~C~olors','Alt+F2',kbaltf2,cmcolors,hcscolors,
         newitem('~A~bout','',kbnokey,cmabout,hcsabout,
         nil))),
       nil))))
     ));
end;

procedure mapp.newfile;
var
  dialog : pdialog;
  r : trect;
  control : word;
  b : pview;
  dyr,ddy,dmn,dse,d10 : word;
begin

  r.assign(0,0,40,6);
  r.move(15,5);
  dialog := new(pdialog,init(r,'New records file'));
  with dialog^ do
  begin
    r.assign(5,3,15,5);
    insert(new(pbutton,init(r,'~O~k',cmok,bfdefault)));
    r.assign(25,3,35,5);
    insert(new(pbutton,init(r,'Cancel',cmcancel,bfnormal)));
    r.assign(20,1,30,2);
    b := new(pinputline,init(r,8));
    insert(b);
    b^.helpctx := hccompanyname;
    r.assign(5,1,19,2);
    insert(new(plabel,init(r,'File name',b)));
  end;
  dialog^.setdata(f);
  control := desktop^.execview(dialog);
  if control <> cmcancel then dialog^.getdata(f);
  if control <> cmcancel then
  begin
       enablecommands(mycommandset);
       f.ilename := f.ilename + '.sfr';
       assign(fi,f.ilename);
       rewrite(fi,1);
       getdate(dyr,ddy,dmn,d10);
       if dyr < 2000 then dyr := dyr - 1900 else dyr := dyr - 2000;
       lastid := dyr*1000;
       blockwrite(fi,lastid,4);
  end;
end;

procedure mapp.Colors;
var
  D: PColorDialog;
begin
  D := New(PColorDialog, Init('',
    ColorGroup('Desktop',       DesktopColorItems(nil),
    ColorGroup('Menus',         MenuColorItems(nil),
    ColorGroup('Windows',  DialogColorItems(dpGrayDialog, nil),
    ColorGroup('Quickhelp', WindowColorItems(wpBlueWindow, nil),
      nil))))));

  {D^.HelpCtx := hcOCColorsDBox;}

  if ExecuteDialog(D, Application^.GetPalette) <> cmCancel then
  begin
    DoneMemory;    { Dispose all group buffers }
    ReDraw;        { Redraw application with new palette }
  end;
end;



procedure mapp.openfile;
var
  dialog : pdialog;
  r : trect;
  control : word;
  b : pview;
begin

  r.assign(0,0,40,6);
  r.move(15,5);
  dialog := new(pdialog,init(r,'Open records file'));
  with dialog^ do
  begin
    r.assign(5,3,15,5);
    insert(new(pbutton,init(r,'~O~k',cmok,bfdefault)));
    r.assign(25,3,35,5);
    insert(new(pbutton,init(r,'Cancel',cmcancel,bfnormal)));
    r.assign(20,1,30,2);
    b := new(pinputline,init(r,8));
    insert(b);
    b^.helpctx := hccompanyname;
    r.assign(5,1,19,2);
    insert(new(plabel,init(r,'File name',b)));
  end;
  dialog^.setdata(f);
  control := desktop^.execview(dialog);
  if control <> cmcancel then dialog^.getdata(f);
  if control <> cmcancel then
  begin
       enablecommands(mycommandset);
       f.ilename := f.ilename + '.sfr';
       assign(fi,f.ilename);
       {$i-}
       reset(fi,1);
       blockread(fi,lastid,4);
       {$i+}
       if ioresult <> 0 then
       begin
            disablecommands(mycommandset);
            badfile;
       end;
  end;

end;

procedure findinvoice;
var
   dialog : pdialog;
   r : trect;
   control : word;
   b : pview;
begin
  r.assign(10,5,34,12);
  dialog := new(pdialog, init(r,'Enter #'));
  with dialog^ do
  begin
       r.assign(2,2,22,3);
       b := new(pinputline,init(r,15));
       insert(b);
       b^.helpctx := hcfindinvoice;
       r.assign(1,4,11,6);
       insert(new(pbutton,init(r,'~O~k',cmok,bfdefault)));
       r.assign(12,4,22,6);
       insert(new(pbutton,init(r,'Cancel',cmcancel,bfnormal)));
  end;
  dialog^.setdata(f);
  control := desktop^.execview(dialog);
  if control <> cmcancel then dialog^.getdata(i);
  if control = cmcancel then i.nvoice := 'Vivardein';
end;



procedure mapp.verifyinvoice;
var
   dialog : pdialog;
   b : pview;
   control : word;
   r : trect;
begin
  r.assign(14,1,45,21);
  dialog := new(pdialog,init(r,'Student Data'));
  with dialog^ do
  begin
       r.assign(2,2,14,3);
       b := new(pinputline,init(r,10));
       insert(b);
       b^.helpctx := hcenternumber;
       r.assign(2,1,13,2);
       insert(new(plabel,init(r,'First name',b)));

       r.assign(2,4,14,7);
       b := new(pinputline,init(r,10));
       insert(b);
       b^.helpctx := hcenterpaymethod;
       r.assign(2,3,18,4);
       insert(new(plabel,init(r,'Middle name',b)));

       r.assign(2,6,14,7);
       b := new(pinputline,init(r,10));
       insert(b);
       b^.helpctx := hcentersubtotal;
       r.assign(2,5,18,6);
       insert(new(plabel,init(r,'Last name',b)));

       r.assign(2,8,14,9);
       b := new(pinputline,init(r,10));
       insert(b);
       b^.helpctx := hcentertaxcollected;
       r.assign(2,7,18,8);
       insert(new(plabel,init(r,'Teacher',b)));

       r.assign(2,10,9,11);
       b := new(pinputline,init(r,5));
       insert(b);
       b^.helpctx := hcenterproductcost;
       r.assign(2,9,18,10);
       insert(new(plabel,init(r,'ID #',b)));

       r.assign(2,12,9,13);
       b := new(pinputline,init(r,5));
       insert(b);
       r.assign(2,11,18,12);
       insert(new(plabel,init(r,'ZIP Code',b)));


       r.assign(16,2,28,3);
       b := new(pinputline,init(r,20));
       insert(b);
       b^.helpctx := hcnochange;
       r.assign(16,1,27,2);
       insert(new(plabel,init(r,'Address',b)));

       r.assign(16,4,29,5);
       b := new(pinputline,init(r,11));
       insert(b);
       b^.helpctx := hcenternontaxable;
       r.assign(16,3,29,4);
       insert(new(plabel,init(r,'Phone #',b)));

       r.assign(16,6,28,7);
       b := new(pinputline,init(r,10));
       insert(b);
       b^.helpctx := hcnochange;
       r.assign(16,5,28,6);
       insert(new(plabel,init(r,'City',b)));

       r.assign(16,8,21,9);
       b := new(pinputline,init(r,2));
       insert(b);
       b^.helpctx := hcnochange;
       r.assign(16,7,28,8);
       insert(new(plabel,init(r,'State',b)));

       r.assign(16,10,21,11);
       b := new(pinputline,init(r,2));
       insert(b);
       b^.helpctx := hcnochange;
       r.assign(16,9,28,10);
       insert(new(plabel,init(r,'Grade',b)));

       r.assign(2,17,14,19);
       insert(new(pbutton,init(r,'~C~ontinue',cmok,bfdefault)));
       r.assign(17,17,27,19);
       insert(new(pbutton,init(r,'Cancel',cmcancel,bfnormal)));

       r.assign(2,14,12,15);
       b := new(pinputline,init(r,8));
       insert(b);
       r.assign(2,13,18,14);
       insert(new(plabel,init(r,'Entry Date',b)));

       r.assign(16,14,26,15);
       b := new(pinputline,init(r,8));
       insert(b);
       r.assign(16,13,30,14);
       insert(new(plabel,init(r,'Withdrawl',b)));

       {b := new(pinputline,init(r,15));
       insert(b);
       b^.helpctx := hcenterdate;
       r.assign(1,1,11,2);
       insert(new(plabel,init(r,'Last name',b)));}
  end;
  dialog^.setdata(tinvoice);
  control := desktop^.execview(dialog);
  if control <> cmcancel then dialog^.getdata(tinvoice);
end;

procedure mapp.parents;
var
   dialog : pdialog;
   b : pview;
   control : word;
   r : trect;
begin
  r.assign(14,3,45,13);
  dialog := new(pdialog,init(r,'Parent Data'));
  with dialog^ do
  begin
       r.assign(2,2,14,3);
       b := new(pinputline,init(r,20));
       insert(b);
       b^.helpctx := hcenternumber;
       r.assign(2,1,13,2);
       insert(new(plabel,init(r,'Father',b)));

       r.assign(2,4,15,5);
       b := new(pinputline,init(r,11));
       insert(b);
       b^.helpctx := hcenterpaymethod;
       r.assign(2,3,18,4);
       insert(new(plabel,init(r,'Work #',b)));

       r.assign(16,2,28,3);
       b := new(pinputline,init(r,20));
       insert(b);
       b^.helpctx := hcnochange;
       r.assign(16,1,27,2);
       insert(new(plabel,init(r,'Mother',b)));

       r.assign(16,4,29,5);
       b := new(pinputline,init(r,11));
       insert(b);
       b^.helpctx := hcenternontaxable;
       r.assign(16,3,29,4);
       insert(new(plabel,init(r,'Work #',b)));

       r.assign(2,7,14,9);
       insert(new(pbutton,init(r,'~C~ontinue',cmok,bfdefault)));
       r.assign(17,7,27,9);
       insert(new(pbutton,init(r,'Cancel',cmcancel,bfnormal)));


       {b := new(pinputline,init(r,15));
       insert(b);
       b^.helpctx := hcenterdate;
       r.assign(1,1,11,2);
       insert(new(plabel,init(r,'Last name',b)));}
  end;
  dialog^.setdata(parvar);
  control := desktop^.execview(dialog);
  if control <> cmcancel then dialog^.getdata(parvar);
end;

procedure mapp.nation;
var
   dialog : pdialog;
   b : pview;
   control : word;
   r : trect;
begin
  r.assign(14,3,44,15);
  dialog := new(pdialog,init(r,'Nationality'));
  with dialog^ do
  begin
       r.assign(2,2,20,3);
          insert(new(pstatictext,init(r,'')));
          r.assign(5,2,23,7);
          b := new(pradiobuttons,init(r,
                  newsitem('~C~aucasian',
                  newsitem('~H~ispanic',
                  newsitem('~B~lack',
                  newsitem('~N~ative Am.',
                  newsitem('~O~ther / N/A',nil)))))));
          insert(b);
          b^.helpctx := hcdestination;
       r.assign(2,9,14,11);
       insert(new(pbutton,init(r,'~C~ontinue',cmok,bfdefault)));
       r.assign(17,9,27,11);
       insert(new(pbutton,init(r,'Cancel',cmcancel,bfnormal)));
  end;
  dialog^.setdata(nat);
  control := desktop^.execview(dialog);
  if control <> cmcancel then dialog^.getdata(nat);
end;

procedure mapp.language;
var
   dialog : pdialog;
   b : pview;
   control : word;
   r : trect;
begin
  r.assign(12,3,54,13);
  dialog := new(pdialog,init(r,'Nationality'));
  with dialog^ do
  begin
       r.assign(2,1,20,2);
          insert(new(pstatictext,init(r,'Home Pref.')));
          r.assign(2,2,20,5);
          b := new(pradiobuttons,init(r,
                  newsitem('~E~nglish',
                  newsitem('~S~panish',
                  newsitem('~O~ther',nil)))));
          insert(b);
          b^.helpctx := hcdestination;
          r.assign(22,1,40,2);
          insert(new(pstatictext,init(r,'School Pref.')));
          r.assign(22,2,40,5);
          b := new(pradiobuttons,init(r,
                  newsitem('~E~nglish',
                  newsitem('~S~panish',
                  newsitem('~O~ther',nil)))));
          insert(b);
          b^.helpctx := hcdestination;
       r.assign(2,7,14,9);
       insert(new(pbutton,init(r,'~C~ontinue',cmok,bfdefault)));
       r.assign(17,7,27,9);
       insert(new(pbutton,init(r,'Cancel',cmcancel,bfnormal)));
  end;
  dialog^.setdata(lag);
  control := desktop^.execview(dialog);
  if control <> cmcancel then dialog^.getdata(lag);
end;

procedure mapp.savestu;
begin
     tag(fi);
     with final do
     begin
          studentfo := tinvoice;
          parentfo := parvar;
          nationfo := nat;
          langfo := lag;
     end;
     blockwrite(fi,final,sizeof(final));
end;

procedure editinvoice;
var
   dialog : pdialog;
   b : pview;
   control : word;
   r : trect;
begin
  r.assign(10,3,55,17);
  dialog := new(pdialog,init(r,'Edit data'));
  with dialog^ do
  begin
       r.assign(1,4,17,5);
       b := new(pinputline,init(r,15));
       insert(b);
       b^.helpctx := hcenternumber;
       r.assign(1,3,9,4);
       insert(new(plabel,init(r,'Number',b)));
       r.assign(1,6,17,7);
       b := new(pinputline,init(r,15));
       insert(b);
       b^.helpctx := hcenterpaymethod;
       r.assign(1,5,15,6);
       insert(new(plabel,init(r,'Pay Method',b)));
       r.assign(26,2,36,3);
       b := new(pinputline,init(r,8));
       insert(b);
       b^.helpctx := hcentersubtotal;
       r.assign(25,1,36,2);
       insert(new(plabel,init(r,'Subtotal',b)));
       r.assign(26,4,36,5);
       b := new(pinputline,init(r,8));
       insert(b);
       b^.helpctx := hcentertaxcollected;
       r.assign(25,3,39,4);
       insert(new(plabel,init(r,'Tax Collected',b)));
       r.assign(26,6,36,7);
       b := new(pinputline,init(r,8));
       insert(b);
       b^.helpctx := hcenterproductcost;
       r.assign(25,5,39,6);
       insert(new(plabel,init(r,'Product Cost',b)));
       r.assign(1,8,11,9);
       b := new(pinputline,init(r,8));
       insert(b);
       b^.helpctx := hcnochange;
       r.assign(1,7,15,8);
       insert(new(plabel,init(r,'Profit',b)));
       r.assign(26,8,36,9);
       b := new(pinputline,init(r,8));
       insert(b);
       b^.helpctx := hcenternontaxable;
       r.assign(25,7,39,8);
       insert(new(plabel,init(r,'Non-Taxable',b)));
       r.assign(1,10,11,11);
       b := new(pinputline,init(r,8));
       insert(b);
       b^.helpctx := hcnochange;
       r.assign(1,9,16,10);
       insert(new(plabel,init(r,'Tax to collect',b)));
       r.assign(15,11,25,13);
       insert(new(pbutton,init(r,'~V~erify',cmok,bfdefault)));
       r.assign(29,11,39,13);
       insert(new(pbutton,init(r,'Cancel',cmcancel,bfnormal)));
       r.assign(1,2,11,3);
       b := new(pinputline,init(r,8));
       insert(b);
       b^.helpctx := hcenterdate;
       r.assign(1,1,6,2);
       insert(new(plabel,init(r,'Date',b)));
  end;
  dialog^.setdata(tinvoice);
  control := desktop^.execview(dialog);
  if control <> cmcancel then dialog^.getdata(tinvoice);
  if control <> cmcancel then
  begin

       blockwrite(fi,tinvoice,sizeinvoice);
  end;
end;


procedure mapp.badfile;
begin
     messagebox('File not found.  Using current or default list values.',
     nil,mferror+mfokbutton);
end;

procedure mapp.calculatorerror;
begin
     messagebox('No values to calculate.  You must create at least 1 set of values.',
     nil,mferror+mfokbutton);
end;

function tatusline.hint(ahelpctx : word) : string;
var
strin : string;
begin
     case ahelpctx of
          hcsnewinvoice : strin := 'Create new invoice list';
          hcsopeninvoice : strin := 'Open saved invoice list';
          hcsprintinvoice : strin := 'Print invoice list totals';
          hcsnewv : strin := 'Place new invoice at end of list';
          hcsfindv : strin := 'Find & edit invoice in current list';
          hcsviewval : strin := 'View invoice list totals';
          hcfilemenu : strin := 'Invoice list options';
          hcinvoicemenu : strin := 'Invoice options';
          hccalcvalue : strin := 'Calcuate invoice list values';
          hcaddress : strin := 'Enter Street & Number';
          hccity : strin := 'Enter City, State & Zip Code';
          hccitytax : strin := 'Enter city sales tax rate';
          hcstatetax : strin := 'Enter state sales tax rate';
          hcnochange : strin := 'DO NOT CHANGE THE VALUES IN THIS BOX!!';
          hccompanyname : strin := 'Enter the company name';
          hcentername : strin := 'Enter the name saved as';
          hcfindinvoice : strin := 'Enter the invoice number to find';
          hcenternumber : strin := 'Enter the invoice number';
          hcenterpaymethod : strin := 'Enter the payment method';
          hcentersubtotal : strin := 'Enter the invoice subtotal';
          hcentertaxcollected : strin := 'Enter taxes you have collected';
          hcenterproductcost : strin := 'Enter your costs on the product';
          hcenternontaxable : strin := 'Enter amount of non-taxable dollars';
          hcenterdate : strin := 'Enter the invoice date';
          hcdestination : strin := 'Choose print destination (File = PRINT.TXT)';
          hctype : strin := 'Choose print format';
          hcspecial : strin := 'Special functions & options';
          hcsexit : strin := 'Exit the program';
          hcscolors : strin := 'Change the appearance of the program';
          hcquickhelp : strin := 'Open the ''QuickHelp'' program overview';
          hcsabout : strin := 'About InvoiceMaster';
          0 : strin := 'StudenTrack          Press F1 for help';
     else
         strin := '';
     end;
hint := strin;
end;

function CalcHelpName: PathStr;
var
  EXEName: PathStr;
  Dir: DirStr;
  Name: NameStr;
  Ext: ExtStr;
begin
  EXEName := FSearch('NNVOICES.EXE', GetEnv('PATH'));
  FSplit(EXEName, Dir, Name, Ext);
  if Dir[Length(Dir)] = '\' then Dec(Dir[0]);
  CalcHelpName := FSearch('INVOICES.HLP', Dir);
end;



procedure nosuch;
begin
     messagebox('Invoice not found.',nil,mferror + mfokbutton);
end;

procedure mapp.GetEvent(var Event: TEvent);
var
  W: PWindow;
  HFile: PHelpFile;
  HelpStrm: PDosStream;
const
  HelpInUse: Boolean = False;
begin
  inherited GetEvent(Event);
  case Event.What of
    evCommand:
      if (Event.Command = cmHelp)  and not HelpInUse then
      begin
        HelpInUse := True;
        HelpStrm := New(PDosStream, Init(CalcHelpName, stOpenRead));
        HFile := New(PHelpFile, Init(HelpStrm));
        if HelpStrm^.Status <> stOk then
        begin
          MessageBox('Could not open help file.', nil, mfError + mfOkButton);
          Dispose(HFile, Done);
        end
        else
        begin
          W := New(PHelpWindow,Init(HFile, GetHelpCtx));
          if ValidView(W) <> nil then
          begin
            ExecView(W);
            Dispose(W, Done);
          end;
          ClearEvent(Event);
        end;
        HelpInUse := False;
      end;
    evMouseDown:
      if Event.Buttons <> 1 then Event.What := evNothing;
  end;
end;




procedure helpwindow;
var
   w : word;
begin
     messagebox('Quickview',nil,mfinformation + mfokbutton);
end;



procedure mapp.InitStatusLine;
var
  R: TRect;
begin
  GetExtent(R);
  R.A.Y := R.B.Y - 1;
  StatusLine := New(PtatusLine, Init(R,
    NewStatusDef(0, $FFFF,
      NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
      newstatuskey('~F1~ Help',kbf1,cmhelp,
      nil)),
    nil)));
end;



procedure mapp.handleevent(var event : tevent);

begin

  tapplication.handleevent(event);
  if (event.what = evnothing) and (welcomenumber = false) then
  begin
       registerhelpfile;
       welcomenumber := true;
       welcome;
  end;

  if event.what = evcommand then
  begin
    case event.command of
      cmhelpwindow : helpwindow;
      cmcolors : colors;
      cmnewfile : begin
                       newfile;

                  end;
      cmopenfile : begin
                        f.ilename := '________';
                        openfile;
                   end;


      cmnewinvoice : begin
                          {val(tinvoice.subtotal,real1,waste);
                          val(tinvoice.productcost,real2,waste);
                          real1 := real1-real2;
                          str(real1:8:2,tinvoice.profit);
                          val(tinvoice.subtotal,real1,waste);
                          val(tinvoice.nontaxable,real2,waste);
                          real1 := real1-real2;
                          val(info.taxcity,real3,waste);
                          val(info.taxstate,real2,waste);
                          real2 := real2 + real3;
                          real1 := real1 * real2/100;
                          str(real1:8:2,tinvoice.taxtoget);
                                    }
                          verifyinvoice;
                          parents;
                          nation;
                          language;
                          savestu;
                     end;

    cmabout : welcome;
    cmfindinvoice : begin
                         looknum := 0;
                         reset(fi,1);
                         verifyinvoice;
                         parents;
                         nation;
                         language;
                         while (not eof(fi)) and (looknum < 10) do
                         begin
                              compat := 0;
                              blockread(fi,look,sizeof(look));
                              if look.studentfo.first = tinvoice.first then inc(compat);
                              if look.studentfo.mid = tinvoice.mid then inc(compat);
                              if look.studentfo.last = tinvoice.last then inc(compat);
                              if look.studentfo.id = tinvoice.id then inc(compat);

                         {if i.nvoice <> 'Vivardein' then
                         begin
                              reset(fi,1);
                              blockread(fi,info,sizeinfo);
                              repeat
                                    blockread(fi,tinvoice,sizeinvoice);
                              until (tinvoice.number = i.nvoice) or (filepos(fi) = filesize(fi));
                              if tinvoice.number = i.nvoice then
                              begin
                                   seek(fi,filepos(fi) - sizeinvoice);
                                   newinvoice;
                                   val(tinvoice.subtotal,real1,waste);
                                   val(tinvoice.productcost,real2,waste);
                                   real1 := real1-real2;
                                   str(real1:8:2,tinvoice.profit);
                                   val(tinvoice.subtotal,real1,waste);
                                   val(tinvoice.nontaxable,real2,waste);
                                   real1 := real1-real2;
                                   val(info.taxcity,real3,waste);
                                   val(info.taxstate,real2,waste);
                                   real2 := real2 + real3;
                                   real1 := real1 * real2/100;
                                   str(real1:8:2,tinvoice.taxtoget);
                                   editinvoice;

                              end
                              else
                                  nosuch;
                              end;  }
                    end;
                    end;
    else
      exit;
    end;
    clearevent(event);
  end;
end;


begin
     welcomenumber := false;
     mycommandset := [cmnewinvoice,cmfindinvoice,cmviewvalues];
     printcommandset := [cmprintfile];
     tapp.disablecommands(mycommandset);
     tapp.disablecommands(printcommandset);
     sizeinfo := sizeof(info);
     sizeinvoice := sizeof(tinvoice);
     with tinvoice do
     begin
          first := '';
          mid := '';

     end;
     f.ilename := '________';
     with info do
     begin
          name := 'Your name here';
          add1 := 'Number & Street';
          add2 := 'City, State, Zip';
          taxcity := '1.5';
          taxsales := '7.25';
          taxstate := '5.75';
     end;
     tapp.init;
     tapp.run;
     tapp.done;

end.
