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

  1. {****************************************}
  2. {    TeeChart. TChart Component          }
  3. { Copyright (c) 1995-98 by David Berneda }
  4. {    All Rights Reserved                 }
  5. {****************************************}
  6. unit uteeblob;
  7.  
  8. interface
  9.  
  10. { Place the TEEBLOB.* files on the \Delphi\Demos\Data folder,
  11.   or change the Table1.DatabaseName property.
  12.  
  13. }
  14.  
  15. { This unit shows how to read a Chart component from a BLOB
  16.   field on a TTable or TQuery component.
  17. }
  18. uses
  19.   WinTypes,WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  20.   Db, DBTables, StdCtrls, Mask, DBCtrls, TeeProcs, TeEngine, Chart,
  21.   ExtCtrls, Grids, DBGrids;
  22.  
  23. type
  24.   TFormChartBlob = class(TForm)
  25.     Table1: TTable;
  26.     DataSource1: TDataSource;
  27.     Chart1: TChart;
  28.     DBGrid1: TDBGrid;
  29.     Panel1: TPanel;
  30.     DBNavigator1: TDBNavigator;
  31.     Button1: TButton;
  32.     Label1: TLabel;
  33.     Label2: TLabel;
  34.     Table1Description: TStringField;
  35.     Table1Chart: TBlobField;
  36.     Panel2: TPanel;
  37.     Button2: TButton;
  38.     Label3: TLabel;
  39.     Label4: TLabel;
  40.     procedure Table1NewRecord(DataSet: TDataSet);
  41.     procedure Table1BeforePost(DataSet: TDataSet);
  42.     procedure DataSource1DataChange(Sender: TObject; Field: TField);
  43.     procedure FormCreate(Sender: TObject);
  44.     procedure Button1Click(Sender: TObject);
  45.     procedure Button2Click(Sender: TObject);
  46.   private
  47.     { Private declarations }
  48.   public
  49.     { Public declarations }
  50.     Saving:Boolean;
  51.     Function ChartInBlob:Boolean;
  52.   end;
  53.  
  54. var
  55.   FormChartBlob: TFormChartBlob;
  56.  
  57. implementation
  58.  
  59. {$R *.DFM}
  60. Uses TeeStore,EditChar;
  61.  
  62. { Create a new Chart when inserting a new record... }
  63. procedure TFormChartBlob.Table1NewRecord(DataSet: TDataSet);
  64. begin
  65.   Chart1.Free;
  66.   Chart1:=TChart.Create(Self);
  67.   Chart1.Parent:=Self;
  68.   Chart1.Align:=alClient;
  69. end;
  70.  
  71. { Save the Chart to the Table record BLOB field }
  72. procedure TFormChartBlob.Table1BeforePost(DataSet: TDataSet);
  73. var tmp:TBlobStream;
  74. begin
  75.   Saving:=True;
  76.   tmp:=TBlobStream.Create(Table1Chart,bmWrite);
  77.   try
  78.     SaveChartToStream(Chart1,tmp);
  79.   finally
  80.     tmp.Free;
  81.   end;
  82.   Saving:=False;
  83. end;
  84.  
  85. { Is the blob field empty ? }
  86. Function TFormChartBlob.ChartInBlob:Boolean;
  87. begin
  88.   with TBlobStream.Create(Table1Chart,bmRead) do
  89.   try
  90.     Result := Size>0;
  91.   finally
  92.     Free;
  93.   end;
  94. end;
  95.  
  96. { re-load another Chart from another BLOB of another record.... }
  97. procedure TFormChartBlob.DataSource1DataChange(Sender: TObject; Field: TField);
  98. var tmp:TBlobStream;
  99.     tmpChart:TCustomChart;
  100. begin
  101.   if (not Saving) and ChartInBlob then
  102.   begin
  103.     tmp:=TBlobStream.Create(Table1Chart,bmRead);
  104.     try
  105.       Chart1.Free;
  106.       tmpChart:=TChart.Create(Self);
  107.       try
  108.         LoadChartFromStream(tmpChart,tmp);
  109.       except
  110.         on E:Exception do ShowMessage(E.Message);
  111.       end;
  112.       Chart1:=TChart(tmpChart);
  113.       Chart1.Align:=alClient;
  114.       Chart1.Parent:=Self;
  115.       Label2.Caption:=IntToStr(tmp.Size);
  116.     finally
  117.       tmp.Free;
  118.     end;
  119.   end;
  120. end;
  121.  
  122. { open the Table }
  123. procedure TFormChartBlob.FormCreate(Sender: TObject);
  124. Var St:String;
  125. begin
  126.   TeeEraseBack:=False;
  127.   Saving:=False;
  128.  
  129.   GetDir(0,St);
  130.   Table1.DataBaseName:=St;
  131.   Table1.Open;
  132. end;
  133.  
  134. { Edit the Chart }
  135. procedure TFormChartBlob.Button1Click(Sender: TObject);
  136. begin
  137.   Table1.Edit;
  138.   EditChart(Self,Chart1);
  139. end;
  140.  
  141. procedure TFormChartBlob.Button2Click(Sender: TObject);
  142. begin
  143.   Close;
  144. end;
  145.  
  146. end.
  147.