home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1996 August / VPR9608A.BIN / del20try / install / data.z / MAIN.PAS < prev    next >
Pascal/Delphi Source File  |  1996-05-08  |  4KB  |  166 lines

  1. {
  2.                      MastApp Main Window.
  3.  
  4.   By default, the database component's alias is DBDEMOS, and so the
  5.   application accesses the Paradox tables. You can upsize the
  6.   application to use Local InterBase data by choosing View | Remote
  7.   Data from the application's main menu.  For this to work, however,
  8.   the Local InterBase Server must be running.  The application checks
  9.   for this and raises an exception if there's a problem.
  10.  
  11.   The application also creates the MASTSQL alias if it doesn't
  12.   already exist.  This code for this appears in the MastData module.
  13.   
  14. }
  15.  
  16. unit Main;
  17.  
  18. interface
  19.  
  20. uses
  21.   SysUtils, Windows, Messages, Classes, Graphics, Controls,
  22.   Forms, Dialogs, Buttons, StdCtrls, Menus, ExtCtrls, DB;
  23.  
  24. type
  25.   TMainForm = class(TForm)
  26.     MainPanel: TPanel;
  27.     OrderBtn: TSpeedButton;
  28.     BrowseBtn: TSpeedButton;
  29.     PartsBtn: TSpeedButton;
  30.     CloseBtn: TSpeedButton;
  31.     HelpBtn: TSpeedButton;
  32.     MainMenu: TMainMenu;
  33.     FileMenu: TMenuItem;
  34.     FileExit: TMenuItem;
  35.     FileNewOrder: TMenuItem;
  36.     ViewMenu: TMenuItem;
  37.     ViewOrders: TMenuItem;
  38.     ViewPartsInventory: TMenuItem;
  39.     ViewStayOnTop: TMenuItem;
  40.     ViewLocal: TMenuItem;
  41.     ViewRemote: TMenuItem;
  42.     HelpMenu: TMenuItem;
  43.     HelpAbout: TMenuItem;
  44.     HelpContents: TMenuItem;
  45.     procedure BrowseCustOrd(Sender: TObject);
  46.     procedure CloseApp(Sender: TObject);
  47.     procedure FormCreate(Sender: TObject);
  48.     procedure BrowseParts(Sender: TObject);
  49.     procedure ToggleStayonTop(Sender: TObject);
  50.     procedure NewOrder(Sender: TObject);
  51.     procedure HelpBtnClick(Sender: TObject);
  52.     procedure AboutClick(Sender: TObject);
  53.     procedure FormDestroy(Sender: TObject);
  54.     procedure ViewLocalClick(Sender: TObject);
  55.     procedure ViewRemoteClick(Sender: TObject);
  56.   private
  57.     procedure CloseAllWindows;
  58.   end;
  59.  
  60. var
  61.   MainForm: TMainForm;
  62.  
  63. implementation
  64.  
  65. uses
  66.    DataMod,  { Data Module }
  67.    BrCstOrd, { The Browse Orders by Customer form }
  68.    BrParts,  { The Browse Parts form }
  69.    EdOrders, { The Edit Orders form }
  70.    QryCust,  { The Specify Date Range form }
  71.    About,    { The About dialog box }
  72.    IniFiles; { Delphi Unit for INI file support }
  73.  
  74. {$R *.DFM}
  75.  
  76. procedure TMainForm.BrowseCustOrd(Sender: TObject);
  77. begin
  78.   BrCustOrdForm.Show;
  79. end;
  80.  
  81. procedure TMainForm.CloseApp(Sender: TObject);
  82. begin
  83.   Close;
  84. end;
  85.  
  86. procedure TMainForm.FormCreate(Sender: TObject);
  87. var
  88.   W: Longint;
  89. begin
  90.   ClientWidth := CloseBtn.Left + CloseBtn.Width + 1;
  91.   ClientHeight := CloseBtn.Top + CloseBtn.Height;
  92.   MainPanel.Align := alClient;
  93.   { position the form at the top of display }
  94.   Left := 0;
  95.   Top := 0;
  96. end;
  97.  
  98. procedure TMainForm.BrowseParts(Sender: TObject);
  99. begin
  100.   BrPartsForm.Show;
  101. end;
  102.  
  103.  
  104. procedure TMainForm.ToggleStayonTop(Sender: TObject);
  105. begin
  106.   with Sender as TMenuItem do
  107.   begin
  108.     Checked := not Checked;
  109.     if Checked then MainForm.FormStyle := fsStayOnTop
  110.     else MainForm.FormStyle := fsNormal;
  111.   end;
  112. end;
  113.  
  114. procedure TMainForm.NewOrder(Sender: TObject);
  115. begin
  116.   EdOrderForm.Enter;
  117. end;
  118.  
  119. procedure TMainForm.HelpBtnClick(Sender: TObject);
  120. begin
  121.   Application.HelpCommand(HELP_CONTENTS, 0);
  122. end;
  123.  
  124. procedure TMainForm.AboutClick(Sender: TObject);
  125. begin
  126.   AboutBox.ShowModal;
  127. end;
  128.  
  129. procedure TMainForm.FormDestroy(Sender: TObject);
  130. begin
  131.   Application.HelpCommand(HELP_QUIT,0);
  132. end;
  133.  
  134. procedure TMainForm.CloseAllWindows;
  135. var
  136.   I: Integer;
  137.   F: TForm;
  138. begin
  139.   for I := 0 to Application.ComponentCount - 1 do
  140.   begin
  141.     if Application.Components[I] is TForm then
  142.     begin
  143.       F := TForm(Application.Components[I]);
  144.       if (F <> Self) and (F.Visible) then F.Close;
  145.     end;
  146.   end;
  147. end;
  148.  
  149. procedure TMainForm.ViewLocalClick(Sender: TObject);
  150. begin
  151.   CloseAllWindows;
  152.   MastData.UseLocalData;
  153.   ViewLocal.Checked := True;
  154.   Caption := Application.Title + ' (Paradox Data)';
  155. end;
  156.  
  157. procedure TMainForm.ViewRemoteClick(Sender: TObject);
  158. begin
  159.   CloseAllWindows;
  160.   MastData.UseRemoteData;
  161.   ViewRemote.Checked := True;
  162.   Caption := Application.Title + ' (Local Interbase)';
  163. end;
  164.  
  165. end.
  166.