home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / OTHER / SAVELOAD / UTEESAVE.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  4.4 KB  |  171 lines

  1. unit uteesave;
  2.  
  3. interface
  4.  
  5. { This form demo shows how to SAVE, EDIT and LOAD Chart components
  6.   from *.TEE files.
  7.  
  8.   It's a mini-editor application.
  9.  
  10.   WARNING:  Turn OFF "Break on Exception" at "Options->Environment".
  11. }
  12. uses
  13.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  14.   Forms, Dialogs, TeEngine, TeeShape, ExtCtrls, TeeProcs, Chart, StdCtrls,
  15.   FileCtrl;
  16.  
  17. type
  18.   TFormVirtual = class(TForm)
  19.     Panel1: TPanel;
  20.     Button1: TButton;
  21.     Panel2: TPanel;
  22.     FileListBox1: TFileListBox;
  23.     DirectoryListBox1: TDirectoryListBox;
  24.     ButtonSave: TButton;
  25.     ButtonSaveAs: TButton;
  26.     Button3: TButton;
  27.     Chart1: TChart;
  28.     ButtonUnZoom: TButton;
  29.     Label1: TLabel;
  30.     Panel3: TPanel;
  31.     procedure Button1Click(Sender: TObject);
  32.     procedure FormCreate(Sender: TObject);
  33.     procedure FileListBox1DblClick(Sender: TObject);
  34.     procedure ButtonSaveClick(Sender: TObject);
  35.     procedure ButtonSaveAsClick(Sender: TObject);
  36.     procedure Button3Click(Sender: TObject);
  37.     procedure ButtonUnZoomClick(Sender: TObject);
  38.     procedure Chart1Zoom(Sender: TObject);
  39.     procedure Chart1Scroll(Sender: TObject);
  40.     procedure Chart1DblClick(Sender: TObject);
  41.   private
  42.     { Private declarations }
  43.   public
  44.     { Public declarations }
  45.     ChartFileName:String;
  46.   end;
  47.  
  48. var
  49.   FormVirtual: TFormVirtual;
  50.  
  51. implementation
  52.  
  53. {$R *.DFM}
  54. uses teeStore,EditPro,ChartPro,TeeLoper,EditChar,TeeCumu;
  55.  
  56. { This example application can be used to create and edit TeeCharts
  57.   saved on disk as *.tee files.
  58.  
  59.   In Delphi 3.0 you can add a TSeriesDataSet component and a DBGrid
  60.   component to visually edit the Chart Series values.
  61. }
  62.  
  63. procedure TFormVirtual.Button1Click(Sender: TObject);
  64. begin
  65.   EditChart(Self,Chart1);
  66.   ButtonSave.Enabled:=True;
  67. end;
  68.  
  69. procedure TFormVirtual.FormCreate(Sender: TObject);
  70. begin
  71.   TeeEraseBack:=False;
  72.   ChartFileName:='';
  73.   DirectoryListBox1.Directory:='';
  74. end;
  75.  
  76. Function YesNo(Const S:String):Boolean;
  77. Var St:Array[0..255] of Char;
  78. begin
  79.   result:=Application.MessageBox(StrPCopy(St,S),'',MB_YESNO)=IDYES;
  80. end;
  81.  
  82. { Load a new Chart from disk... }
  83. procedure TFormVirtual.FileListBox1DblClick(Sender: TObject);
  84. var tmpChart:TCustomChart;
  85. begin
  86.   if (not ButtonSave.Enabled) or
  87.      (YesNo('Chart is modified. Cancel changes?')) then
  88.   begin
  89.     ChartFileName:='';
  90.     Chart1.Free;
  91.     tmpChart:=TChart.Create(Self);
  92.     try
  93.       { WARNING: !!!!!
  94.         If you get here because a "Property does not Exist" EXCEPTION,
  95.         don't worry. Turn off "Break on Exception" at Compiler Options
  96.         and press F9 again.
  97.       }
  98.       LoadChartFromfile(tmpChart,FileListBox1.FileName);
  99.       ChartFileName:=FileListBox1.FileName;
  100.     except
  101.       on E:Exception do ShowMessage(E.Message);
  102.     end;
  103.     Chart1:=tmpChart as TChart;
  104.     With Chart1 do
  105.     begin
  106.       OnZoom:=Chart1Zoom;
  107.       OnScroll:=Chart1Scroll;
  108.       OnDblClick:=Chart1DblClick;
  109.       Align:=alClient;
  110.       Parent:=Self;
  111.     end;
  112.     ButtonSaveAs.Enabled:=False;
  113.     ButtonUnZoom.Enabled:=(not Chart1.LeftAxis.Automatic) or
  114.                           (not Chart1.RightAxis.Automatic) or
  115.                           (not Chart1.TopAxis.Automatic) or
  116.                           (not Chart1.BottomAxis.Automatic);
  117.   end;
  118. end;
  119.  
  120. { Save the current Chart to disk. }
  121. procedure TFormVirtual.ButtonSaveClick(Sender: TObject);
  122. begin
  123.   SaveChartToFile(Chart1,ChartFileName);
  124.   ButtonSave.Enabled:=False;
  125. end;
  126.  
  127. { Save the current Chart as another *.tee file name... }
  128. procedure TFormVirtual.ButtonSaveAsClick(Sender: TObject);
  129. var tmp:String;
  130. begin
  131.   tmp:=SaveChartDialog(Chart1);
  132.   if tmp<>'' then ChartFileName:=tmp;
  133.   FileListBox1.Update;
  134.   FileListBox1.FileName:=ChartFileName;
  135. end;
  136.  
  137. procedure TFormVirtual.Button3Click(Sender: TObject);
  138. begin
  139.   Close;
  140. end;
  141.  
  142. procedure TFormVirtual.ButtonUnZoomClick(Sender: TObject);
  143. begin
  144.   With Chart1 do
  145.   begin
  146.     LeftAxis.Automatic:=True;
  147.     TopAxis.Automatic:=True;
  148.     RightAxis.Automatic:=True;
  149.     BottomAxis.Automatic:=True;
  150.   end;
  151. end;
  152.  
  153. procedure TFormVirtual.Chart1Zoom(Sender: TObject);
  154. begin
  155.   ButtonUnZoom.Enabled:=True;
  156. end;
  157.  
  158. procedure TFormVirtual.Chart1Scroll(Sender: TObject);
  159. begin
  160.   ButtonUnZoom.Enabled:=True;
  161. end;
  162.  
  163. procedure TFormVirtual.Chart1DblClick(Sender: TObject);
  164. begin
  165.   Button1Click(Self);
  166. end;
  167.  
  168. initialization
  169.   RegisterClasses([TCumulative]);
  170. end.
  171.