home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kompon / d123456 / CHEMPLOT.ZIP / Misc / Optnsdlg.pas < prev    next >
Pascal/Delphi Source File  |  2001-05-02  |  6KB  |  187 lines

  1. unit Optnsdlg;
  2.  
  3. {-----------------------------------------------------------------------------
  4. The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  5.  
  6. http://www.mozilla.org/MPL/MPL-1.1.html
  7.  
  8. Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License.
  9.  
  10. The Original Code is: OptionsDlg.pas, released 12 September 2000.
  11.  
  12. The Initial Developer of the Original Code is Mat Ballard.
  13. Portions created by Mat Ballard are Copyright (C) 1999 Mat Ballard.
  14. Portions created by Microsoft are Copyright (C) 1998, 1999 Microsoft Corp.
  15. All Rights Reserved.
  16.  
  17. Contributor(s): Mat Ballard                 e-mail: mat.ballard@chemware.hypermart.net.
  18.  
  19. Last Modified: 05/25/2000
  20. Current Version: 2.00
  21.  
  22. You may retrieve the latest version of this file from:
  23.  
  24.         http://Chemware.hypermart.net/
  25.  
  26. This work was created with the Project JEDI VCL guidelines:
  27.  
  28.         http://www.delphi-jedi.org/Jedi:VCLVCL
  29.  
  30. in mind. 
  31.  
  32.  
  33. Purpose:
  34. This file contains a component wrapper for the Options form.
  35. A component wrapper presents a form as a Delphi Component,
  36. which can be added to the component palette.
  37.  
  38.  
  39. Known Issues:
  40. -----------------------------------------------------------------------------}
  41.  
  42. {$I Misc.inc}
  43.  
  44. interface
  45.  
  46. uses
  47.   Classes, SysUtils,
  48. {$IFDEF WINDOWS}
  49.   WinTypes, WinProcs,
  50.   Forms,
  51. {$ENDIF}
  52. {$IFDEF WIN32}
  53.   Windows,
  54.   Forms,
  55. {$ENDIF}
  56. {$IFDEF LINUX}
  57.   QT,
  58.   QForms,
  59. {$ENDIF}
  60.   Options;
  61.  
  62. const
  63.   TOPTIONSDLG_VERSION = 100;
  64.  
  65. type
  66.   TOptionsDlg = class(TComponent)
  67.   private
  68.     FHelpContext: THelpContext;
  69.     FFormTitle: String;
  70.     FOptionCaption: String;
  71.     FOptionList: TStringList;
  72.     FQuestion: String;
  73.  
  74.   public
  75.     constructor Create(AOwner: TComponent); override;
  76.     {This is the normal constructor. It initializes properties and the list of options.}
  77.     destructor Destroy; override;
  78.     {This is the normal destructor. It frees the list of options.}
  79.     function Execute: Integer;  virtual;
  80.     {This function creates and runs the OptionsBox. It is similar to the Execute
  81.      function of the common dialog boxes, except that it returns an Integer rather
  82.      than a Boolean.}
  83.     {}
  84.     {Its purpose is to display the OptionBox so that the user can pick one option from several.}
  85.  
  86.   published
  87.     property FormTitle: String read FFormTitle write FOptionCaption;
  88.     {This is the title of the Options Dialog.}
  89.     property HelpContext: THelpContext read FHelpContext write FHelpContext;
  90.     {This is the help context of the application's help file
  91.      that describes what this set of options is about.}
  92.     property OptionCaption: String read FOptionCaption write FOptionCaption;
  93.     {This is the caption of the radiogroup of buttons.}
  94.     property OptionList: TStringList read FOptionList write FOptionList;
  95.     {This is the list of options.}
  96.     property Question: String read FQuestion write FQuestion;
  97.     {This is the question that you want the user to answer by picking one option.}
  98.   end;
  99.  
  100. var
  101.   OptionsBox: TOptionsForm;
  102.   {This is the dialog box that asks the user to pick one option out of several.}
  103.   {}
  104.   {It automatically resizes itself according to the number and length of options,
  105.    and the question and caption.}
  106.   {}
  107.   {It is displayed when the Execute method is called.}
  108.  
  109. implementation
  110.  
  111. {------------------------------------------------------------------------------
  112.     Procedure: TOptionsDlg.Create
  113.   Description: standard constructor
  114.        Author: Mat Ballard
  115.  Date created: 04/25/2000
  116. Date modified: 04/25/2000 by Mat Ballard
  117.       Purpose: creates the OptionList, sets various Properties, and adds to the OptionsList
  118.  Known Issues:
  119.  ------------------------------------------------------------------------------}
  120. constructor TOptionsDlg.Create(AOwner: TComponent);
  121. begin
  122.   inherited Create(AOwner);
  123.   FFormTitle := 'Options';
  124.   FOptionCaption := 'Pick an option:';
  125.   FOptionList := TStringList.Create;
  126.   if (csDesigning in ComponentState) then
  127.   begin
  128.     FOptionList.Add('Blue');
  129.     FOptionList.Add('Red');
  130.     FOptionList.Add('Yellow');
  131.     FQuestion := 'What is your favourite colour ?';
  132.   end;
  133. end;
  134.  
  135. {------------------------------------------------------------------------------
  136.     Procedure: TOptionsDlg.Destroy
  137.   Description: standard destructor
  138.        Author: Mat Ballard
  139.  Date created: 04/25/2000
  140. Date modified: 04/25/2000 by Mat Ballard
  141.       Purpose: frees the OptionList
  142.  Known Issues:
  143.  ------------------------------------------------------------------------------}
  144. destructor TOptionsDlg.Destroy;
  145. begin
  146.   FOptionList.Free;
  147.   inherited Destroy;
  148. end;
  149.  
  150. {------------------------------------------------------------------------------
  151.      Function: TOptionsDlg.Execute
  152.   Description: Runs the Options dialog box
  153.        Author: Mat Ballard
  154.  Date created: 04/25/2000
  155. Date modified: 04/25/2000 by Mat Ballard
  156.       Purpose: see Description
  157.  Return Value: the Index, 1..N, of the selected option, or -1 if cancelled
  158.  Known Issues:
  159.  ------------------------------------------------------------------------------}
  160. function TOptionsDlg.Execute: Integer;
  161. var
  162.   i: Integer;
  163. begin
  164.   OptionsBox := TOptionsForm.Create(Application);
  165.   with OptionsBox do
  166.   begin
  167.     Caption := FFormTitle;
  168.     HelpContext := FHelpContext;
  169.     HelpBitBtn.HelpContext := FHelpContext;
  170.     OptionsRadioGroup.Caption := FOptionCaption;
  171.     OptionsRadioGroup.Items.Clear;
  172.     for i := 0 to OptionList.Count-1 do
  173.       OptionsRadioGroup.Items.Add(OptionList.Strings[i]);
  174.     QuestionLabel.Caption := FQuestion;
  175.     DoGeometry;
  176.   end;
  177.  
  178.   try
  179.     Result := OptionsBox.ShowModal;
  180.   finally
  181.     OptionsBox.Free;                    
  182.   end;
  183. end;
  184.  
  185.  
  186. end.
  187.