⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testselectform.pas

📁 delphi编程控件
💻 PAS
字号:
unit TestSelectForm;

{ This is a sample-TTreeSelect-form with two buttons.
  The first button shows how to clear the key-field.
  The second button calls a dialog that allows the user to
  edit the detail-table.
  The OnActivate-event is used to adjust the size of the
  TreeView and the buttons at runtime.
  The height of the form changes if DropdownHeight of the
  calling DbTreeLookupComboBox is not zero, the width changes
  always at runtime.
}

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, Forms,
  StdCtrls, Buttons, ComCtrls, DB, DBTables, dbTree, dbTreeCBox, Menus,
  TreeVwEx;

type
  TSampleTreeSelect = class(TTreeSelect)
    DBTreeView1: TDBTreeView;
    BitBtn1: TBitBtn;
    Label1: TLabel;
    BitBtn2: TBitBtn;
    PopupMenu1: TPopupMenu;
    Test1: TMenuItem;
    N1: TMenuItem;
    Context1: TMenuItem;
    Menu1: TMenuItem;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  end;

var
  SampleTreeSelect: TSampleTreeSelect;

implementation

{$R *.DFM}

{ The dialog that allows the user to make changes at the detail-table: }
uses
  TestEditDetailForm;

procedure TSampleTreeSelect.BitBtn1Click(Sender: TObject);
begin
  DBTreeView.SetFocus;
  CloseUp(caClear);
end;

procedure TSampleTreeSelect.BitBtn2Click(Sender: TObject);
begin
{ Show the dialog that allows the user to make changes at the detail-table: }
  with TfrmEditDetail.Create(self) do
  begin
  { we assume that dtSynchronizeDataSet of the DBTreeView of TfrmEditDetail
    is set at design-time already: }
    Table1.FindKey([self.DBTreeView.SelectedID]);
    ShowModal;
    Free;
  end;
  DBTreeView.SetFocus;
{ DBTreeView.Dataset.Refresh: not needed any more }
  with CallingDbTreeLookupComboBox.DataSource.Dataset do
    if (State = dsBrowse) then
      Refresh;
  CallingDbTreeLookupComboBox.KeyValueChanged;
end;

procedure TSampleTreeSelect.FormActivate(Sender: TObject);
begin
  BitBtn1.Left := 0;
  BitBtn1.Width := ClientWidth DIV 2;
  BitBtn2.Left := BitBtn1.Width + (ClientWidth AND 1);
  BitBtn2.Width := BitBtn1.Width;
  DBTreeView1.Left := 0;
  DBTreeView1.Width := ClientWidth;
  if PosUnderComboBox then
  begin
  { Align buttons on bottom: }
    BitBtn1.Top := ClientHeight - BitBtn1.Height;
    BitBtn2.Top := BitBtn1.Top;
  { Fill the rest of the form with the DBTreeView: }
  { DBTreeView1.Align := alTop; }
    DBTreeView1.Top := 0;
    DBTreeView1.Height := BitBtn1.Top - DBTreeView1.Top;
  end
  else
  begin
  { Align buttons on top: }
    BitBtn1.Top := 0;
    BitBtn2.Top := BitBtn1.Top;
  { Fill the rest of the form with the DBTreeView: }
  { DBTreeView1.Align := alBottom; }
    DBTreeView1.Height := ClientHeight - BitBtn1.Height - BitBtn1.Top;
    DBTreeView1.Top := ClientHeight - DBTreeView1.Height;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -