home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / STANDARD / SQLBARS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  3.1 KB  |  111 lines

  1. {******************************************}
  2. { TeeChart Delphi Component Library        }
  3. { SQL Query Chart Demo                     }
  4. { Copyright (c) 1995-1996 by David Berneda }
  5. { All rights reserved                      }
  6. {******************************************}
  7. unit Sqlbars;
  8.  
  9. interface
  10.  
  11. uses
  12.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  13.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids, DB,
  14.   DBTables, Chart, Series, DbChart, Teengine, TeeProcs;
  15.  
  16. type
  17.   TSQLBarsForm = class(TForm)
  18.     DBChart1: TDBChart;
  19.     DataSource1: TDataSource;
  20.     Panel1: TPanel;
  21.     BarSeries1: TBarSeries;
  22.     Query1: TQuery;
  23.     Panel2: TPanel;
  24.     Memo1: TMemo;
  25.     BitBtn2: TBitBtn;
  26.     ComboBox1: TComboBox;
  27.     Label1: TLabel;
  28.     CBRandomBar: TCheckBox;
  29.     Panel3: TPanel;
  30.     DBGrid1: TDBGrid;
  31.     Label2: TLabel;
  32.     BitBtn1: TBitBtn;
  33.     procedure BitBtn2Click(Sender: TObject);
  34.     procedure ComboBox1Change(Sender: TObject);
  35.     procedure FormCreate(Sender: TObject);
  36.     procedure DBChart1ClickLegend(Sender: TCustomChart;
  37.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  38.     procedure BarSeries1Click(Sender: TChartSeries; ValueIndex: Integer;
  39.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  40.     procedure BarSeries1GetBarStyle(Sender: TCustomBarSeries;
  41.       ValueIndex: Longint; var TheBarStyle: TBarStyle);
  42.     procedure CBRandomBarClick(Sender: TObject);
  43.     procedure BitBtn1Click(Sender: TObject);
  44.   private
  45.     { Private declarations }
  46.   public
  47.     { Public declarations }
  48.   end;
  49.  
  50. implementation
  51.  
  52. {$R *.DFM}
  53. Uses UDemUtil;
  54.  
  55. procedure TSQLBarsForm.BitBtn2Click(Sender: TObject);
  56. begin { rerun the SQL query }
  57.   Screen.Cursor:=crHourGlass;
  58.   try
  59.     Query1.Close;
  60.     Query1.Sql:=Memo1.Lines;
  61.     Query1.Open;
  62.   finally
  63.     Screen.Cursor:=crDefault;
  64.   end;
  65. end;
  66.  
  67. procedure TSQLBarsForm.ComboBox1Change(Sender: TObject);
  68. begin
  69.   if BarSeries1 is TCustomBarSeries then
  70.   BarSeries1.BarStyle:=TBarStyle(ComboBox1.ItemIndex); { <-- change bar style }
  71. end;
  72.  
  73. procedure TSQLBarsForm.FormCreate(Sender: TObject);
  74. begin
  75.   ComboBox1.ItemIndex:=Ord(BarSeries1.BarStyle); { <-- set combobox1 }
  76. end;
  77.  
  78. procedure TSQLBarsForm.DBChart1ClickLegend(Sender: TCustomChart;
  79.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  80. begin
  81.   With DBChart1.Legend do Color:=EditColor(Self,Color);
  82. end;
  83.  
  84. procedure TSQLBarsForm.BarSeries1Click(Sender: TChartSeries;
  85.   ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X,
  86.   Y: Integer);
  87. begin
  88.   With BarSeries1 do
  89.        ValueColor[ValueIndex]:=EditColor(Self,ValueColor[ValueIndex]);
  90. end;
  91.  
  92. procedure TSQLBarsForm.BarSeries1GetBarStyle(Sender: TCustomBarSeries;
  93.   ValueIndex: Longint; var TheBarStyle: TBarStyle);
  94. begin
  95.   if CBRandomBar.Checked then
  96.      TheBarStyle:=TBarStyle(Random(1+Ord(High(TBarStyle))));
  97. end;
  98.  
  99. procedure TSQLBarsForm.CBRandomBarClick(Sender: TObject);
  100. begin
  101.   ComboBox1.Enabled:=not CBRandomBar.Checked;
  102.   DBChart1.Repaint;
  103. end;
  104.  
  105. procedure TSQLBarsForm.BitBtn1Click(Sender: TObject);
  106. begin
  107.   Close;
  108. end;
  109.  
  110. end.
  111.