home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 February / Chip_2004-02_cd1.bin / program / delphi / navody / d56 / ec1vr2.exe / #setuppath# / Delphi / Prnplot / Main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2003-12-09  |  3.4 KB  |  147 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   vivrep20, Db, DBTables, Menus, StdCtrls, ExtCtrls, Buttons;
  8.  
  9. type
  10.   TMainForm = class(TForm)
  11.     MainMenu: TMainMenu;
  12.     PrintItem: TMenuItem;
  13.     PrintSetupItem: TMenuItem;
  14.     ExitItem: TMenuItem;
  15.     AboutItem: TMenuItem;
  16.     SpeedBar: TPanel;
  17.     SpeedButton1: TSpeedButton;  // &Print...
  18.     SpeedButton2: TSpeedButton;  // P&rint Setup...
  19.     SpeedButton3: TSpeedButton;  // E&xit
  20.     SpeedButton4: TSpeedButton;  // &About...
  21.     PrintPreviewItem: TMenuItem;
  22.     SpeedButton5: TSpeedButton;
  23.     Table: TTable;
  24.     DSource: TDataSource;
  25.     Db: TDatabase;
  26.     Group1: TRadioGroup;
  27.     Group2: TRadioGroup;
  28.  
  29.         procedure Print(Sender: TObject);
  30.         procedure PrintSetup(Sender: TObject);
  31.         procedure Exit(Sender: TObject);
  32.         procedure About(Sender: TObject);
  33.         procedure PrintPreview(Sender: TObject);
  34.   private
  35.     { Private declarations }
  36.         procedure GetFunction (var AX,AY: Real; AFi: Real; AIndex: Integer);
  37.         procedure Solve;
  38.   public
  39.     { Public declarations }
  40.      constructor Create (Owner: TComponent); override;
  41.   end;
  42.  
  43. var
  44.   MainForm: TMainForm;
  45.  
  46. implementation
  47.  
  48. uses About, Rep;
  49.  
  50. {$R *.DFM}
  51.  
  52. constructor TMainForm.Create (Owner: TComponent);
  53. begin
  54.   inherited Create (Owner);
  55.    
  56.   Db.Params.Values['PATH'] := Copy (Application.ExeName,0,LastDelimiter ('\',Application.ExeName) - 1);
  57.   Table.Active := true;
  58. end;
  59.  
  60. procedure TMainForm.Print(Sender: TObject);
  61. begin
  62.   Solve;
  63.   if RepForm.VividReport.PrintSetup then RepForm.VividReport.Print;
  64. end;
  65.  
  66. procedure TMainForm.PrintSetup(Sender: TObject);
  67. begin
  68.   RepForm.VividReport.PrinterSetup;
  69. end;
  70.  
  71. procedure TMainForm.Exit(Sender: TObject);
  72. begin
  73.   Close;
  74. end;
  75.  
  76. procedure TMainForm.About(Sender: TObject);
  77. begin
  78.   AboutBox.ShowModal;
  79. end;
  80.  
  81. procedure TMainForm.PrintPreview(Sender: TObject);
  82. begin
  83.   Solve;
  84.   RepForm.VividReport.PrintPreview (RepForm.VRPreview);
  85. end;
  86.  
  87. procedure TMainForm.GetFunction (var AX,AY: Real; AFi: Real; AIndex: Integer);
  88. var
  89.   a,b,l: Real;
  90. begin
  91.  
  92.   case AIndex of
  93.     0:
  94.       begin 
  95.         a := 2;
  96.         b := 5;
  97.         AX := (a+b)*cos(AFi) - a*cos((a+b)*AFi/a);
  98.         AY := (a+b)*sin(AFi) - a*sin((a+b)*AFi/a);
  99.       end;
  100.     1:
  101.       begin
  102.         a := 2;
  103.         b := 12;
  104.         AX := (b-a)*cos(AFi) + a*cos((b-a)*AFi/a);
  105.         AY := (b-a)*sin(AFi) - a*sin((b-a)*AFi/a);
  106.       end;
  107.     2:
  108.       begin
  109.         a := 2;
  110.         b := 8;
  111.         l := 2;
  112.         AX := (b-a)*cos(AFi) + l*a*cos((b-a)*AFi/a);
  113.         AY := (b-a)*sin(AFi) - l*a*sin((b-a)*AFi/a);
  114.       end;
  115.   end;
  116. end;
  117.  
  118. procedure TMainForm.Solve;
  119. var
  120.   x,y,fi: Real;
  121.   APoint: TCurvePoint;
  122. begin
  123.   RepForm.Curve1.CurveData.Items[0].CurvePoints.Clear;
  124.   DSource.Enabled := false;
  125.   Table.EmptyTable;
  126.  
  127.   fi := 0;
  128.   while fi <= 4*Pi do
  129.   begin
  130.     GetFunction (x,y,fi,Group1.ItemIndex);
  131.     APoint := RepForm.Curve1.CurveData.Items[0].CurvePoints.Add as TCurvePoint;
  132.     APoint.Argument.Value := x;
  133.     APoint._Function.Value := y;
  134.  
  135.     GetFunction (x,y,fi,Group2.ItemIndex);
  136.     Table.AppendRecord ([x,y]);
  137.     fi := fi + Pi/30;
  138.   end;
  139.  
  140.   DSource.Enabled := true;
  141.  
  142.   (RepForm.Curve1.Legend.Data as TLegendAbsString).Value := Group1.Items.Strings[Group1.ItemIndex];
  143.   (RepForm.Curve2.Legend.Data as TLegendAbsString).Value := Group2.Items.Strings[Group2.ItemIndex];
  144. end;
  145.  
  146. end.
  147.