home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / CBPLUS32.ZIP / LUFORM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-03  |  14.9 KB  |  464 lines

  1. unit Luform;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, DBGrids,
  8.   DBLookup, Tabs, ExtCtrls,  Spin, NewRec, DB, DBTables,
  9.   DBCtrls, Grids, Buttons, Dblup1a, Dblup1b;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     Notebook1: TNotebook;
  14.     TabSet1: TTabSet;
  15.       RadioGroupStylePg2: TRadioGroup;
  16.     Table1: TTable;
  17.     DataSource1: TDataSource;
  18.     DBGrid1: TDBGrid;
  19.     DBNavigator1: TDBNavigator;
  20.     Bevel1: TBevel;
  21.     CheckBoxLUActive: TCheckBox;
  22.     CheckBoxAutoDropDown: TCheckBox;
  23.     CheckBoxHideBorder: TCheckBox;
  24.     CheckBoxCtl3D: TCheckBox;
  25.     CheckBoxSpeedButton: TCheckBox;
  26.     CheckBoxAlignHorz: TCheckBox;
  27.     CheckBoxAlignVert: TCheckBox;
  28.     CheckBoxListTitles: TCheckBox;
  29.     CheckBoxListColLines: TCheckBox;
  30.     CheckBoxListRowLines: TCheckBox;
  31.     Shape1: TShape;
  32.     SpinButton1: TSpinButton;
  33.     FontDialog1: TFontDialog;
  34.     ButtonFieldColor: TButton;
  35.     ColorDialog1: TColorDialog;
  36.     ButtonFieldFont: TButton;
  37.     ButtonListFont: TButton;
  38.     ButtonListColor: TButton;
  39.     ButtonTitle: TButton;
  40.     CheckBoxOwnerDraw: TCheckBox;
  41.     Memo1: TMemo;
  42.     Shape2: TShape;
  43.     DBComboBoxPlus1: TDBComboBoxPlus;
  44.     Bevel2: TBevel;
  45.     Shape3: TShape;
  46.     SpinButton2: TSpinButton;
  47.     ComboBoxPlus1: TComboBoxPlus;
  48.     CheckBoxLUActive2: TCheckBox;
  49.     RadioGroupStyle2: TRadioGroup;
  50.     CheckBoxDropDown2: TCheckBox;
  51.     CheckBoxBorder2: TCheckBox;
  52.     CheckBoxCtrl3D2: TCheckBox;
  53.     CheckBoxSpeedButton2: TCheckBox;
  54.     CheckBoxHrozAlign2: TCheckBox;
  55.     CheckBoxVertAlign2: TCheckBox;
  56.     CheckBoxTitles2: TCheckBox;
  57.     CheckBoxColLines2: TCheckBox;
  58.     CheckBoxRowLines2: TCheckBox;
  59.     CheckBoxOwnerDraw2: TCheckBox;
  60.     ButtonFieldColor2: TButton;
  61.     ButtonFieldFont2: TButton;
  62.     ButtonListColor2: TButton;
  63.     ButtonListFont2: TButton;
  64.     ButtonTitleColor2: TButton;
  65.     Memo2: TMemo;
  66.     Shape4: TShape;
  67.     LabelValue: TLabel;
  68.     Label2Value: TLabel;
  69.     Shape5: TShape;
  70.     MemoPg0: TMemo;
  71.     Label1: TLabel;
  72.     Label2: TLabel;
  73.     Label3: TLabel;
  74.     procedure FormActivate(Sender: TObject);
  75.     procedure TabSet1Click(Sender: TObject);
  76.     procedure RadioGroupStylePg2Click(Sender: TObject);
  77.     procedure FormDeactivate(Sender: TObject);
  78.     procedure CheckBoxLUActiveClick(Sender: TObject);
  79.     procedure CheckBoxAutoDropDownClick(Sender: TObject);
  80.     procedure CheckBoxHideBorderClick(Sender: TObject);
  81.     procedure CheckBoxCtl3DClick(Sender: TObject);
  82.     procedure CheckBoxSpeedButtonClick(Sender: TObject);
  83.     procedure CheckBoxAlignHorzClick(Sender: TObject);
  84.     procedure CheckBoxAlignVertClick(Sender: TObject);
  85.     procedure CheckBoxListTitlesClick(Sender: TObject);
  86.     procedure CheckBoxListColLinesClick(Sender: TObject);
  87.     procedure CheckBoxListRowLinesClick(Sender: TObject);
  88.     procedure SpinButton1DownClick(Sender: TObject);
  89.     procedure SpinButton1UpClick(Sender: TObject);
  90.     procedure ButtonFieldColorClick(Sender: TObject);
  91.     procedure ButtonFieldFontClick(Sender: TObject);
  92.     procedure ButtonListFontClick(Sender: TObject);
  93.     procedure ButtonListColorClick(Sender: TObject);
  94.     procedure ButtonTitleClick(Sender: TObject);
  95.     procedure DBComboBoxPlus1NewLookupRec(Sender: TObject;
  96.       var Cancelled: Boolean);
  97.     procedure DBComboBoxPlus1DrawCell(Sender: TObject; Col, Row: Longint;
  98.       Rect: TRect; State: TGridDrawState);
  99.     procedure ComboBoxPlus1Change(Sender: TObject);
  100.   private
  101.     { Private declarations }
  102.     ComboBox : TComboBoxPlus;
  103.     procedure LoadDropDownData(Combo: TComboBoxPlus; ColsOfData: Integer);
  104.     procedure CreateDemoTable;
  105.   public
  106.     { Public declarations }
  107.   end;
  108.  
  109. var
  110.   Form1: TForm1;
  111.  
  112. implementation
  113.  
  114. {$R *.DFM}
  115.  
  116. procedure TForm1.LoadDropDownData(Combo : TComboBoxPlus; ColsOfData : Integer);
  117. begin
  118.   {Flush the old data}
  119.   Combo.ClearGridData;
  120.   {Make sure the allocated storage is big enough}
  121.   Combo.RowCount := 20;
  122.   Combo.ColCount := ColsOfData + 1;
  123.   {Load the data}
  124.  
  125.   Combo.AddRow(['0',   'Company'               ,'Years'              ,'Owner']);
  126.   Combo.AddRow(['1221','Kauai Dive Shoppe'     ,'12'                 ,'Paul' ]);
  127.   Combo.AddRow(['1680','Island Finders'        ,''                   ,'Willie']);
  128.   Combo.AddRow(['3158','Action Divers Supply'  ,'2'                  ,'Matt' ]);
  129.   Combo.AddRow(['2135','Frank''s Divers Supply','8'                  ,'Frank']);
  130.   Combo.AddRow(['5515','Ocean Adventures'      ,'234'                ,'Sally']);
  131.   Combo.AddRow(['3042','Gold Coast Supply'     ,'4'                  ,'Lucy' ]);
  132.   Combo.AddRow(['5432','Divers-for-Hire'       ,'6'                  ,'Laura']);
  133.   Combo.AddRow(['5384','Tora Tora Tora'        ,'A very long time'   ,'Ben'  ]);
  134.   Combo.AddRow(['1231','Unisco'                ,'4'                  ,'Susan']);
  135.   Combo.AddRow(['6312','Aquatic Drama'         ,'26'                 ,'Gizmo']);
  136.   Combo.AddRow(['1563','Blue Sports'           ,'13'                 ,'Jim'  ]);
  137.   Combo.AddRow(['1351','Sight Diver'           ,'5'                  ,'Juice']);
  138.   Combo.AddRow(['1384','VIP Divers Club'       ,'32'                 ,''     ]);
  139.   {Now shring the grid so its just big enough for the data}
  140.   Combo.SizeGridToData;
  141. end;
  142.  
  143. procedure TForm1.CreateDemoTable;
  144. begin
  145.   with Table1 do
  146.   begin
  147.     Active := False;
  148.     TableType := ttParadox;
  149.     with FieldDefs do
  150.       begin
  151.       Clear;
  152.       Add('Company', ftString, 50, True);
  153.     end;
  154.     CreateTable;
  155.     Active := True;
  156.     Insert;
  157.     SetFields(['1221']);
  158.     Post;
  159.     Insert;
  160.     SetFields(['5384']);
  161.     Post;
  162.     Insert;
  163.     SetFields(['1563']);
  164.     Post;
  165.   end;
  166.  end;
  167.  
  168. procedure TForm1.FormActivate(Sender: TObject);
  169. begin
  170.   LoadDropDownData(DBComboBoxPlus1, 3);
  171.   LoadDropDownData(ComboBoxPlus1, 3);
  172.   CreateDemoTable;
  173.   ComboBox := DBComboBoxPlus1;
  174.   Notebook1.PageIndex :=  0;
  175.   TabSet1.TabIndex := 0;
  176. end;
  177.  
  178. procedure TForm1.FormDeactivate(Sender: TObject);
  179. begin
  180.   Table1.Active := False;
  181.   Table1.DeleteTable;
  182. end;
  183.  
  184.  
  185. procedure TForm1.TabSet1Click(Sender: TObject);
  186. begin
  187.   Notebook1.PageIndex := TabSet1.TabIndex;
  188.   case Notebook1.PageIndex of
  189.    0 : exit;
  190.    1 : ComboBox := DBComboBoxPlus1;
  191.    2 : ComboBox := ComboBoxPlus1;
  192.   end;
  193.   ComboBox.SetFocus;
  194. end;
  195.  
  196. procedure TForm1.RadioGroupStylePg2Click(Sender: TObject);
  197. begin
  198.   case TRadioGroup(Sender).ItemIndex of
  199.     0 : ComboBox.Style := TComboPlusStyle(csDropDown);
  200.     1 : ComboBox.Style := TComboPlusStyle(csDropDownList);
  201.     2 : ComboBox.Style := TComboPlusStyle(csIncSearch);
  202.     3 : ComboBox.Style := TComboPlusStyle(csIncSrchEdit);
  203.   end; {case}
  204.   { get fresh data for the new drop down style }
  205.   LoadDropDownData(ComboBox,3);
  206.   ComboBox.SetFocus;
  207. end;
  208.  
  209. procedure TForm1.CheckBoxLUActiveClick(Sender: TObject);
  210. begin
  211.   ComboBox.LookupActive := TCheckBox(Sender).Checked;
  212.   ComboBox.SetFocus;
  213. end;
  214.  
  215. procedure TForm1.CheckBoxAutoDropDownClick(Sender: TObject);
  216. begin
  217.   ComboBox.AutoDropDown := TCheckBox(Sender).Checked;
  218.   ComboBox.SetFocus;
  219. end;
  220.  
  221. procedure TForm1.CheckBoxHideBorderClick(Sender: TObject);
  222. begin
  223.   if TCheckBox(Sender).Checked then
  224.     ComboBox.BorderStyle := bsNone
  225.   else
  226.     ComboBox.BorderStyle := bsSingle;
  227.   ComboBox.SetFocus;
  228. end;
  229.  
  230. procedure TForm1.CheckBoxCtl3DClick(Sender: TObject);
  231. begin
  232.   ComboBox.Ctl3D := TCheckBox(Sender).Checked;
  233.   ComboBox.SetFocus;
  234. end;
  235.  
  236. procedure TForm1.CheckBoxSpeedButtonClick(Sender: TObject);
  237. begin
  238.   ComboBox.ShowSpeedButton := TCheckBox(Sender).Checked;
  239.   ComboBox.SetFocus;
  240. end;
  241.  
  242. procedure TForm1.CheckBoxAlignHorzClick(Sender: TObject);
  243. begin
  244.   if TCheckBox(Sender).Checked then
  245.     ComboBox.DropDownAlign := Dblup1a.Left
  246.   else
  247.     ComboBox.DropDownAlign := Dblup1a.Right;
  248.   ComboBox.SetFocus;
  249. end;
  250.  
  251. procedure TForm1.CheckBoxAlignVertClick(Sender: TObject);
  252. begin
  253.   if TCheckBox(Sender).Checked then
  254.     ComboBox.DropDownTop := Dblup1a.Above
  255.   else
  256.     ComboBox.DropDownTop := Dblup1a.Below;
  257.   ComboBox.SetFocus;
  258. end;
  259.  
  260. procedure TForm1.CheckBoxListTitlesClick(Sender: TObject);
  261. begin
  262.   if TCheckBox(Sender).Checked then
  263.     ComboBox.FixedRows := 1
  264.   else
  265.     ComboBox.FixedRows := 0;
  266.   LoadDropDownData(ComboBox, 3);
  267.   ComboBox.SetFocus;
  268. end;
  269.  
  270. procedure TForm1.CheckBoxListColLinesClick(Sender: TObject);
  271. begin
  272.   If TCheckBox(Sender).Checked then
  273.     ComboBox.Options := ComboBox.Options + [TStringGridPOptions(loColLines)]
  274.   else
  275.     ComboBox.Options := ComboBox.Options - [TStringGridPOptions(loColLines)];
  276.   ComboBox.SetFocus;
  277. end;
  278.  
  279. procedure TForm1.CheckBoxListRowLinesClick(Sender: TObject);
  280. begin
  281.   If TCheckBox(Sender).Checked then
  282.     ComboBox.Options := ComboBox.Options + [TStringGridPOptions(loRowLines)]
  283.   else
  284.     ComboBox.Options := ComboBox.Options - [TStringGridPOptions(loRowLines)];
  285.   ComboBox.SetFocus;
  286. end;
  287.  
  288. procedure TForm1.SpinButton1DownClick(Sender: TObject);
  289. begin
  290.   ComboBox.Height := ComboBox.Height + 1;
  291.   Case TabSet1.TabIndex of
  292.     1 : begin
  293.          Shape1.Height := ComboBox.Height + 10;
  294.          SpinButton1.Height := ComboBox.Height;
  295.         end;
  296.     2 : begin
  297.          Shape2.Height := ComboBox.Height + 10;
  298.          SpinButton2.Height := ComboBox.Height;
  299.         end;
  300.    end; {case}
  301. end;
  302.  
  303. procedure TForm1.SpinButton1UpClick(Sender: TObject);
  304. begin
  305.   ComboBox.Height := ComboBox.Height - 1;
  306.   Case TabSet1.TabIndex of
  307.     1 : begin
  308.           Shape1.Height := ComboBox.Height + 10;
  309.           SpinButton1.Height := ComboBox.Height;
  310.         end;
  311.     2 : begin
  312.           Shape2.Height := ComboBox.Height + 10;
  313.           SpinButton2.Height := ComboBox.Height;
  314.         end;
  315.    end; {case}
  316. end;
  317.  
  318. procedure TForm1.ButtonFieldColorClick(Sender: TObject);
  319. begin
  320.   ColorDialog1.Color := ComboBox.Color;
  321.   If ColorDialog1.Execute then
  322.     ComboBox.Color := ColorDialog1.Color;
  323.   ComboBox.SetFocus;
  324. end;
  325.  
  326. procedure TForm1.ButtonFieldFontClick(Sender: TObject);
  327. begin
  328.   FontDialog1.Font := ComboBox.Font;
  329.   If FontDialog1.Execute then
  330.     ComboBox.Font := FontDialog1.Font;
  331.   ComboBox.SetFocus;
  332. end;
  333.  
  334. procedure TForm1.ButtonListFontClick(Sender: TObject);
  335. begin
  336.   FontDialog1.Font := ComboBox.ListFont;
  337.   If FontDialog1.Execute then
  338.   begin
  339.     ComboBox.ListFont := FontDialog1.Font;
  340.     ComboBox.DefaultRowHeight := ComboBox.ListFont.Size + ComboBox.ListFont.Size div 3;
  341.  {    4 - ComboBox.ListFont.height * 72 div ComboBox.ListFont.PixelsPerInch;}
  342.  
  343.   end;
  344.   ComboBox.SizeGridToData;
  345.   ComboBox.SetFocus;
  346. end;
  347.  
  348. procedure TForm1.ButtonListColorClick(Sender: TObject);
  349. begin
  350.   ColorDialog1.Color := ComboBox.ListColor;
  351.   If ColorDialog1.Execute then
  352.     ComboBox.ListColor := ColorDialog1.Color;
  353.   ComboBox.SetFocus;
  354. end;
  355.  
  356. procedure TForm1.ButtonTitleClick(Sender: TObject);
  357. begin
  358.   ColorDialog1.Color := ComboBox.TitleColor;
  359.   If ColorDialog1.Execute then
  360.     ComboBox.TItleColor := ColorDialog1.Color;
  361.   ComboBox.SetFocus;
  362. end;
  363.  
  364. procedure TForm1.DBComboBoxPlus1NewLookupRec(Sender: TObject;
  365.   var Cancelled: Boolean);
  366. begin
  367.   Cancelled := False;                 {Set cancelled to false initially}
  368.   {make room for new record}
  369.   ComboBox.RowCount := ComboBox.RowCount + 1;
  370.   {Fillin the company field}
  371.   FormNewRec.EditCompany.Text := ComboBox.DisplayValue;
  372.  
  373.   FormNewRec.ShowModal;                { display the dialog box }
  374.   if FormNewRec.ModalResult=mrOK then  {if user pressed OK then save the new SubCat}
  375.   begin
  376.     ComboBox.AddRow([FormNewRec.EditIDNo.Text,
  377.                      FormNewRec.EditCompany.Text,
  378.                      FormNewRec.EditYears.Text,
  379.                      FormNewRec.EditOwner.Text]);
  380.     ComboBox.DisplayValue := FormNewRec.EditCompany.Text;
  381.   end
  382.   else
  383.   begin
  384.     ComboBox.DisplayValue := '';
  385.     Cancelled := True;
  386.   end;
  387.   {shrink the grid so it just fits the data}
  388.   ComboBox.SizeGridToData;
  389. end;
  390.  
  391. procedure TForm1.DBComboBoxPlus1DrawCell(Sender: TObject; Col, Row: Longint;
  392.   Rect: TRect; State: TGridDrawState);
  393. var
  394.   MyRect : TRect;
  395.   { As a special bonus we show how to draw random Smileys
  396.     Note that these Smilies automatically size themselves to the cell height}
  397.   Procedure DrawSmiley(Canvas : TCanvas; aRect : TRect);
  398.   var
  399.     OldPen : TPen;
  400.     OldBrush : TBrush;
  401.   begin
  402.     OldPen   := Canvas.Pen;
  403.     OldBrush := Canvas.Brush;
  404.     Canvas.Brush.Color := clYellow;
  405.     if (State = [gdSelected]) then
  406.       Canvas.Brush.Color := clFuchsia;
  407.     Canvas.Pen.Color := clBlack;
  408.     Canvas.Pen.Width := (ARect.Bottom - ARect.Top) div 20;
  409.     if Canvas.Pen.Width = 0 then Canvas.Pen.Width := 1;
  410.     Canvas.Ellipse(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
  411.     Canvas.Brush.Color := clBlack;
  412.     {Left eye}
  413.     Canvas.Ellipse(ARect.Left + ((ARect.Right - ARect.Left) div 3) - ((ARect.Right - ARect.Left) div 10),
  414.                      ARect.Top + ((ARect.Bottom - ARect.Top) div 3) - ((ARect.Bottom - ARect.Top) div 10),
  415.                      ARect.Left + ((ARect.Right - ARect.Left) div 3) + ((ARect.Right - ARect.Left) div 10),
  416.                      ARect.Top + ((ARect.Bottom - ARect.Top) div 3) + ((ARect.Bottom - ARect.Top) div 10));
  417.     (* Simple algebra simplifies the above to the following but it dosnt look as good}
  418.     Canvas.Ellipse((23 * ARect.Left + 7 * ARect.Right) div 30,
  419.                    (23 * ARect.Top + 7 * ARect.Bottom) div 30,
  420.                    (17 * ARect.Left + 13 * ARect.Right) div 30,
  421.                    (17 * ARect.Top + 13 * ARect.Bottom) div 30); *)
  422.     {Right eye}
  423.     Canvas.Ellipse(ARect.Left + ((ARect.Right - ARect.Left) div 3)*2 - ((ARect.Right - ARect.Left) div 10),
  424.                    ARect.Top + ((ARect.Bottom - ARect.Top) div 3) - ((ARect.Bottom - ARect.Top) div 10),
  425.                    ARect.Left + ((ARect.Right - ARect.Left) div 3)*2 + ((ARect.Right - ARect.Left) div 10),
  426.                    ARect.Top + ((ARect.Bottom - ARect.Top) div 3) + ((ARect.Bottom - ARect.Top) div 10));
  427.     {Smile}
  428.     Canvas.Arc(ARect.Left + ((ARect.Right - ARect.Left) div 6),
  429.                ARect.Top + ((ARect.Bottom - ARect.Top) div 4),
  430.                ARect.Left + ((ARect.Right - ARect.Left) div 6)*5,
  431.                ARect.Top + ((ARect.Bottom - ARect.Top) div 6)*5,
  432.                ARect.Left + ((ARect.Right - ARect.Left) div 4),
  433.                ARect.Top + ((ARect.Bottom - ARect.Top) div 2),
  434.                ARect.Left + (((ARect.Right - ARect.Left) div 4)*3),
  435.                ARect.Top + ((ARect.Bottom - ARect.Top) div 2));
  436.     Canvas.Pen   := OldPen;
  437.     Canvas.Brush := OldBrush;
  438.   end;
  439.  
  440. begin
  441.   if (TabSet1.TabIndex = 1) and
  442.     not CheckBoxOwnerDraw.Checked then exit;
  443.   if (TabSet1.TabIndex = 2) and
  444.     not CheckBoxOwnerDraw2.Checked then exit;
  445.   If (Row >= ComboBox.FixedRows) and (col = 0) then
  446.   begin
  447.     MyRect.Left   := Rect.Right - Rect.Bottom + Rect.Top;
  448.     MyRect.Top    := Rect.Top;
  449.     MyRect.Right  := MyRect.Left + Rect.Bottom - Rect.Top;
  450.     MyRect.Bottom := Rect.Bottom;
  451.     DrawSmiley(ComboBox.ListCanvas, MyRect);
  452.   end;
  453.   ComboBox.SetFocus;
  454. end;
  455.  
  456. procedure TForm1.ComboBoxPlus1Change(Sender: TObject);
  457. begin
  458.   LabelValue.Caption := ComboBoxPlus1.Value;
  459. end;
  460.  
  461. end.
  462.  
  463.  
  464.