home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / chap11 / morefunc / main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-21  |  2.0 KB  |  99 lines

  1. unit Main;
  2.  
  3. { Program copyright (c) 1995 by Charles Calvert }
  4. { Project Name: MOREFUNC }
  5.  
  6. { Examples of calling some of the functions in
  7.   the MATHBOX unit. Be sure MATHBOX is on your
  8.   Library Path in the Options | Environment | Library Path
  9.   menu option. }
  10.  
  11. interface
  12.  
  13. uses
  14.   WinTypes, WinProcs, Classes,
  15.   Graphics, Controls, Forms,
  16.   StdCtrls, ExtCtrls;
  17.  
  18. type
  19.   TCalcType = (TXToTheY, TArcSin, TArcCos, TLogXY);
  20.  
  21. type
  22.   TForm1 = class(TForm)
  23.     BCalc: TButton;
  24.     Panel1: TPanel;
  25.     Edit1: TEdit;
  26.     Edit2: TEdit;
  27.     Label1: TLabel;
  28.     Label2: TLabel;
  29.     Label3: TLabel;
  30.     Panel2: TPanel;
  31.     RBXToTheY: TRadioButton;
  32.     RBArcSin: TRadioButton;
  33.     RBArcCos: TRadioButton;
  34.     RBLogYX: TRadioButton;
  35.     BClose: TButton;
  36.     procedure BCalcClick(Sender: TObject);
  37.     procedure FormCreate(Sender: TObject);
  38.     procedure RBClick(Sender: TObject);
  39.     procedure BCloseClick(Sender: TObject);
  40.   private
  41.     CalcType: TCalcType;
  42.   end;
  43.  
  44. var
  45.   Form1: TForm1;
  46.  
  47. implementation
  48.  
  49. uses
  50.   MathBox;
  51.  
  52. {$R *.DFM}
  53.  
  54. procedure TForm1.BCalcClick(Sender: TObject);
  55. var
  56.   r, x, y: Real;
  57. begin
  58.   x := Str2Real(Edit1.Text);
  59.   y := Str2Real(Edit2.Text);
  60.   Label1.Caption := 'Invalid Input';
  61.   case CalcType of
  62.     TXToTheY: r := XToTheY(x, y);
  63.     TArcSin:  if (x < 1.0) and (x > -1.0) then
  64.                 r := ArcSin(x)
  65.               else
  66.                 Exit;
  67.     TArcCos:  if (x < 1.0) and (x > -1.0) then
  68.                 r := ArcCos(x)
  69.               else
  70.                 Exit;
  71.     TLogXY:   if y <> 1 then
  72.                 r := LogXY(x, y);
  73.                else
  74.                 Exit;
  75.   end;
  76.   Label1.Caption := Real2Str(r, 2 ,2);
  77. end;
  78.  
  79. procedure TForm1.FormCreate(Sender: TObject);
  80. begin
  81.   Edit1.Text := '';
  82.   Edit2.Text := '';
  83.   Label1.Caption := '';
  84.   RBXToTheY.Checked := True;
  85.   CalcType := TXToTheY;
  86. end;
  87.  
  88. procedure TForm1.RBClick(Sender: TObject);
  89. begin
  90.   CalcType := TCalcType((Sender as TRadioButton).Tag);
  91. end;
  92.  
  93. procedure TForm1.BCloseClick(Sender: TObject);
  94. begin
  95.   Close;
  96. end;
  97.  
  98. end.
  99.