home *** CD-ROM | disk | FTP | other *** search
/ PC Expert 29 / Pce29cd.iso / RUNIMAGE / DELPHI40 / DEMOS / TEECHART / SQLBARS.PAS < prev    next >
Pascal/Delphi Source File  |  1998-06-16  |  3KB  |  105 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.     BitBtn1: TBitBtn;
  22.     BarSeries1: TBarSeries;
  23.     Query1: TQuery;
  24.     Panel2: TPanel;
  25.     Memo1: TMemo;
  26.     BitBtn2: TBitBtn;
  27.     ComboBox1: TComboBox;
  28.     Label1: TLabel;
  29.     CBRandomBar: TCheckBox;
  30.     Panel3: TPanel;
  31.     DBGrid1: TDBGrid;
  32.     Label2: TLabel;
  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.   private
  44.     { Private declarations }
  45.   public
  46.     { Public declarations }
  47.   end;
  48.  
  49. implementation
  50.  
  51. {$R *.DFM}
  52. Uses UDemUtil;
  53.  
  54. procedure TSQLBarsForm.BitBtn2Click(Sender: TObject);
  55. begin { rerun the SQL query }
  56.   Screen.Cursor:=crHourGlass;
  57.   try
  58.     Query1.Close;
  59.     Query1.Sql:=Memo1.Lines;
  60.     Query1.Open;
  61.   finally
  62.     Screen.Cursor:=crDefault;
  63.   end;
  64. end;
  65.  
  66. procedure TSQLBarsForm.ComboBox1Change(Sender: TObject);
  67. begin
  68.   if BarSeries1 is TCustomBarSeries then
  69.   BarSeries1.BarStyle:=TBarStyle(ComboBox1.ItemIndex); { <-- change bar style }
  70. end;
  71.  
  72. procedure TSQLBarsForm.FormCreate(Sender: TObject);
  73. begin
  74.   ComboBox1.ItemIndex:=Ord(BarSeries1.BarStyle); { <-- set combobox1 }
  75. end;
  76.  
  77. procedure TSQLBarsForm.DBChart1ClickLegend(Sender: TCustomChart;
  78.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  79. begin
  80.   With DBChart1.Legend do Color:=EditColor(Self,Color);
  81. end;
  82.  
  83. procedure TSQLBarsForm.BarSeries1Click(Sender: TChartSeries;
  84.   ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X,
  85.   Y: Integer);
  86. begin
  87.   With BarSeries1 do
  88.        ValueColor[ValueIndex]:=EditColor(Self,ValueColor[ValueIndex]);
  89. end;
  90.  
  91. procedure TSQLBarsForm.BarSeries1GetBarStyle(Sender: TCustomBarSeries;
  92.   ValueIndex: Longint; var TheBarStyle: TBarStyle);
  93. begin
  94.   if CBRandomBar.Checked then
  95.      TheBarStyle:=TBarStyle(Random(1+Ord(High(TBarStyle))));
  96. end;
  97.  
  98. procedure TSQLBarsForm.CBRandomBarClick(Sender: TObject);
  99. begin
  100.   ComboBox1.Enabled:=not CBRandomBar.Checked;
  101.   DBChart1.Repaint;
  102. end;
  103.  
  104. end.
  105.