home *** CD-ROM | disk | FTP | other *** search
/ Delphi 4 Bible / Delphi_4_Bible_Tom_Swan_IDG_Books_1998.iso / source / MayTemp / Main.pas < prev    next >
Pascal/Delphi Source File  |  1998-05-12  |  3KB  |  97 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls,
  7.   Forms, Dialogs, TeEngine, Series, ExtCtrls, TeeProcs, Chart,
  8.   StdCtrls, Buttons, TeCanvas;
  9.  
  10. type
  11.   TMainForm = class(TForm)
  12.     Chart1: TChart;
  13.     Series1: TLineSeries;
  14.     Series2: TLineSeries;
  15.     Series4: TLineSeries;
  16.     Series5: TLineSeries;
  17.     Series6: TLineSeries;
  18.     Series3: TLineSeries;
  19.     BitBtn1: TBitBtn;
  20.     procedure FormActivate(Sender: TObject);
  21.   private
  22.     { Private declarations }
  23.   public
  24.     { Public declarations }
  25.   end;
  26.  
  27. var
  28.   MainForm: TMainForm;
  29.  
  30. implementation
  31.  
  32. {$R *.DFM}
  33.  
  34. { Change the following pathname if your data file is
  35.   in another location. The pathname is relative to the
  36.   current directory, which is assumed to be at the
  37.   same level as \Data\. }
  38.  
  39. const
  40.   FileName = '..\Data\KeyWestMayClimate.txt';
  41.  
  42. { The following procedure is called when the form is first
  43.   activated. At that time, the program opens the data file,
  44.   reads its values, and adds them to the chart's series
  45.   objects. }
  46.  
  47. procedure TMainForm.FormActivate(Sender: TObject);
  48. var
  49.   F: TextFile;                   // File variable
  50.   Date: Integer;                 // First column in file data
  51.   NormalHigh : Integer;          // Next column
  52.   NormalLow : Integer;           // and so on ...
  53.   RecordHigh : Integer;
  54.   RecordHighYear : Integer;
  55.   RecordLow : Integer;
  56.   RecordLowYear : Integer;
  57.   ColdestMaximum : Integer;
  58.   ColdestMaximumYear : Integer;
  59.   WarmestMaximum : Integer;      // ... down to the
  60.   WarmestMaximumYear : Integer;  // Last column in file data
  61. begin
  62.   AssignFile(F, FileName);   // Initialize file variable
  63.   Reset(F);                  // Open the file
  64.   while not Eof(F) do        // Loop until the end of the file
  65.   begin
  66.     Read(F,                  // Read one row of data
  67.       Date,                  // into the individual variables.
  68.       NormalHigh,
  69.       NormalLow,
  70.       RecordHigh,
  71.       RecordHighYear,
  72.       RecordLow,
  73.       RecordLowYear,
  74.       ColdestMaximum,
  75.       ColdestMaximumYear,
  76.       WarmestMaximum,
  77.       WarmestMaximumYear);   // End of Read statement
  78.  
  79.     { One row of file data has been loaded at this point. The
  80.       following statements add the data points to each of the
  81.       line chart's six series objects. The empty string
  82.       arguments can be used to label data points. These
  83.       strings aren't used here because the X axis of this
  84.       sample chart already shows day values (1, 2, ..., 31). }
  85.  
  86.     Series1.AddXY(Date, NormalHigh, '', clTeeColor);
  87.     Series2.AddXY(Date, NormalLow, '', clTeeColor);
  88.     Series3.AddXY(Date, RecordHigh, '', clTeeColor);
  89.     Series4.AddXY(Date, RecordLow, '', clTeeColor);
  90.     Series5.AddXY(Date, ColdestMaximum, '', clTeeColor);
  91.     Series6.AddXY(Date, WarmestMaximum, '', clTeeColor);
  92.  
  93.   end;
  94. end;
  95.  
  96. end.
  97.