home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_PAS / TVTOYS.ZIP / COMSLECT.PAS < prev    next >
Pascal/Delphi Source File  |  1994-01-03  |  5KB  |  178 lines

  1. (***************************************************************************
  2.   COMSelect unit
  3.   Select COM port dialog
  4.   PJB October 8, 1993, CompuServe mail to INTERNET:d91-pbr@nada.kth.se
  5.   Copyright 1993, All Rights Reserved
  6.   Free source, use at your own risk.
  7.   If modified, please state so if you pass this around.
  8.  
  9.   This is just some code I used for a project of mine where the
  10.   baud rate and parity were fixed. You'll have to make another dialog
  11.   if you want to control more parameters at the same time.
  12.  
  13. ***************************************************************************)
  14. unit COMSlect;
  15.  
  16. interface
  17.  
  18.   uses
  19.     App, Objects, Dialogs, Views, Validate,
  20.     toyPrefs, {$I hcFile}
  21.     TVUtils;
  22.  
  23.   var
  24.     COMDataRec :
  25.       record
  26.         SelectCOM : Word;      {RadioButtons}
  27.         COMAdr    : Word;      {Inputline (hex)}
  28.         IRQ       : LongInt;   {Inputline (Range)}
  29.       end;
  30.  
  31.  
  32.   function MakeCOMSelectDialog:PDialog;
  33.  
  34.  
  35. (***************************************************************************
  36. ***************************************************************************)
  37. implementation
  38.  
  39.  
  40.   type
  41.     PCOMRadio = ^TCOMRadio;
  42.     TCOMRadio =
  43.       object (TRadioButtons)
  44.         procedure Draw; virtual;
  45.       end;
  46.  
  47.   var
  48.     COMAdr : PInputLine;
  49.     COMIRQ : PInputLine;
  50.     COMRadio : PCOMRadio;
  51.  
  52.  
  53. (***************************************************************************
  54. ***************************************************************************)
  55.  
  56.  
  57.   (*******************************************************************
  58.     Updates the input lines if the user changes COM port
  59.   *******************************************************************)
  60.   procedure TCOMRadio.Draw;
  61.     var
  62.       l : Longint;
  63.   begin
  64.     inherited Draw;
  65.     if Sel<4 then
  66.     begin
  67.       COMAdr^.Options:=COMAdr^.Options and not ofSelectable;
  68.       COMIRQ^.Options:=COMIRQ^.Options and not ofSelectable;
  69.       COMAdr^.SetData(MemW[Seg0040:Sel*2]);
  70.       l:=4-(Sel and 1);
  71.       COMIRQ^.SetData(l);
  72.     end
  73.     else
  74.     begin
  75.       COMAdr^.Options:=COMAdr^.Options or ofSelectable;
  76.       COMIRQ^.Options:=COMIRQ^.Options or ofSelectable;
  77.     end;
  78.   end;
  79.  
  80.  
  81. (***************************************************************************
  82. ***************************************************************************)
  83.  
  84.   (*******************************************************************
  85.     Scan through the BIOS entries for non-zero COM port addresses
  86.   *******************************************************************)
  87.   procedure CheckActiveCOMS;
  88.     var
  89.       i    : Integer;
  90.       Mask : Word;
  91.   begin
  92.     Mask:=0;
  93.     for i:=0 to 3 do
  94.       if MemW[Seg0040:i*2]=0 then
  95.         Inc(Mask, 1 SHL i);
  96.  
  97.     if COMRadio<>Nil then
  98.       COMRadio^.SetButtonState(Mask, False);
  99.   end;
  100.  
  101.  
  102.   (*******************************************************************
  103.     This code generated by Dialog Design 4.0 available by anonymous
  104.     ftp to garbo.uwasa.fi  /pc/turbovis. Thanks to David Baldwin
  105.   *******************************************************************)
  106.   function MakeCOMSelectDialog:PDialog;
  107.     var
  108.       Dlg : PDialog;
  109.       R : TRect;
  110.       Control : PView;
  111.   begin
  112.     R.Assign(19,14,61,27);
  113.     New(Dlg, Init(R, 'COM Port Selection'));
  114.     Dlg^.Options := $1343;
  115.  
  116.     R.Assign(6,3,18,8);
  117.     COMRadio := New(PCOMRadio, Init(R,
  118.       NewSItem('COM ~1~',
  119.       NewSItem('COM ~2~',
  120.       NewSItem('COM ~3~',
  121.       NewSItem('COM ~4~',
  122.       NewSItem('~O~ther',Nil)))))));
  123.     Dlg^.HelpCtx := hctoyCOMRadio;
  124.     Dlg^.Insert(COMRadio);
  125.  
  126.     R.Assign(5,2,14,3);
  127.     Dlg^.Insert(New(PLabel, Init(R, 'COM ~P~ort', COMRadio)));
  128.  
  129.     R.Assign(25,4,31,5);
  130.     COMAdr := New(PInputLine, Init(R, 4));
  131.     COMAdr^.HelpCtx := hctoyCOMPortAdr;
  132.     Dlg^.Insert(COMAdr);
  133.  
  134.     COMAdr^.Validator := New(PHexValidator, Init(0,$FFFF));
  135.  
  136.     R.Assign(24,3,36,4);
  137.     Dlg^.Insert(New(PLabel, Init(R, 'COM ~A~ddress', COMAdr)));
  138.  
  139.     R.Assign(25,7,29,8);
  140.     COMIRQ := New(PInputLine, Init(R, 2));
  141.     COMIRQ^.HelpCtx := hctoyCOMIRQ;
  142.     Dlg^.Insert(COMIRQ);
  143.  
  144.     COMIRQ^.Validator := New(PRangeValidator, Init(0, 16));
  145.     COMIRQ^.Validator^.Options := voTransfer;
  146.  
  147.     R.Assign(24,6,28,7);
  148.     Dlg^.Insert(New(PLabel, Init(R, '~I~RQ', COMIRQ)));
  149.  
  150.     R.Assign(4,10,14,12);
  151.     Control := New(PButton, Init(R, 'O~K~', cmOK, bfDefault));
  152.     Control^.HelpCtx := hcOK;
  153.     Dlg^.Insert(Control);
  154.  
  155.     R.Assign(16,10,26,12);
  156.     Control := New(PButton, Init(R, 'Cancel', cmCancel, bfNormal));
  157.     Control^.HelpCtx := hcCancel;
  158.     Dlg^.Insert(Control);
  159.  
  160.     R.Assign(28,10,38,12);
  161.     Control := New(PButton, Init(R, 'Help', cmHelp, bfNormal));
  162.     Dlg^.Insert(Control);
  163.  
  164.     R.Assign(32,4,35,5);
  165.     Control := New(PStaticText, Init(R, 'hex'));
  166.     Dlg^.Insert(Control);
  167.     Dlg^.SelectNext(False);
  168.  
  169.     CheckActiveCOMS;
  170.  
  171.     MakeCOMSelectDialog:=Dlg;
  172.   end;
  173.  
  174.  
  175. end.
  176.  
  177.  
  178.