宝马娱乐在线城-宝马娱乐在线

来自 互联网络 2019-11-13 15:10 的文章
当前位置: 宝马娱乐在线城 > 互联网络 > 正文

宝马娱乐在线城下拉选择框

interface

type
TPopupPanel = class(TCustomPanel)
private
procedure griddblclick(sender: TObject);
protected
public
DSP: TDataSetProvider;
CDS: TClientDataSet;
DS: TDataSource;
Grid: tdbgrid;
dataset: TDataSet;
listdataset: TDataSet;
datafield: string;
datafieldcn: string;
listfields: string;
listfieldscn: string;
panelwidth: integer;
panelheight: integer;
search: integer;
constructor create(owner: TComponent); override;
procedure createcols;
end;

implementation

 

destructor tdbpanel.destroy;
begin
  freeeditors;
  inherited des

if (AControl.Top + AControl.Height > WorkArea.Bottom) then
begin
if (HostP.y - WorkArea.Top > WorkArea.Bottom - HostP.y - HostControl.Height) then
AControl.Top := HostP.y - AControl.Height;
end;

{ 创建各字段的数据输入控件的方法}
procedure tdbpanel.createeditors(ds: tdatasource; colcount: integer);
var
  i, n, rowcount: integer;
  textheight: integer;
begin
  if datasource.dataset.active then begin
    n := datasource.dataset.fieldcount;
    { 计算最大的标题长度及显示长度}
    datasource.dataset.first;
    { 计算高度}
    textheight := canvas.textheight(datasource
    .dataset.fields[0].displaylabel) + flineheight; file://10;
    { 计算行列数}
    rowcount := n div columns;
    if n mod columns <> 0 then inc(rowcount);
    { 分配内存}
    freeeditors;
    setlength(editors, n);
    setlength(labels, n);
    { 创建滚动盒}
    fscrollbox := tscrollbox.create(owner);
    fscrollbox.parent := self;
    fscrollbox.align := alclient;
    { 创建编辑}
    for i:=0 to n-1 do begin
      { 创建标题}
      labels[i] := tlabel.create(owner);
      labels[i].parent := fscrollbox; file://self;
      labels[i].caption := datasource.dataset.fields[i].displaylabel;
      labels[i].left := fleft + (maxlabellen +
      maxtextlen + 10) * (i div rowcount);
      labels[i].width := maxlabellen;
      labels[i].top := ftop + (i mod rowcount) * textheight + 5;
      { 创建编辑对象}
      editors[i] := tdbcombobox.create(owner);
      editors[i].parent := fscrollbox; file://self;
      editors[i].left := labels[i].left + labels[i].width;
      editors[i].width := maxtextlen;
      editors[i].top := ftop + (i mod rowcount) * textheight;
      editors[i].datasource := datasource;
      editors[i].datafield := datasource.dataset.fields[i].fieldname;
      editors[i].onkeypress := akeypress;
      editors[i].onkeydown := akeydown;
    end;
    { 创建ok按钮}
    okbutton := tbutton.create(owner);
    okbutton.parent := fscrollbox;
    okbutton.left := editors[n-1].left;
    okbutton.top := editors[n-1].top + textheight;
    okbutton.caption := 确定;
    okbutton.onclick := fclick;
  end;
end;

TYNSearch(self.search).Text := self.CDS.fieldbyname(self.datafieldcn).Text;

type
  TDBPanel = class(tpanel)
  private
    { private declarations }
    fleft: integer;
    ftop: integer;
    maxtextlen: integer;
    maxlabellen: integer;
    fscrollbox: tscrollbox;        {滚动控件}
    flineheight: integer;
    fclick: tnotifyevent;
    editors: array of tdbcombobox;
file://- >具体进行编辑所用的数据控件数组,动态生成
    labels: array of tlabel;
file://- >各字段的标题,动态生成
    okbutton: tbutton;
file://- >最后增加的确定按钮,用于实现提交动作。
    { 数据源}
    fdatasource: tdatasource;
    fcolumns: integer;
file://- >输入表格的列数
    protected
    { protected declarations }
    procedure freeeditors;
file://- >释放数据输入控件的内存
    public
    procedure createeditors(ds: tdatasource; colcount: integer);
file://- >创建各字段的数据输入控件
    constructor create(aowner:
    tcomponent); override;
    destructor destroy; override;
    procedure akeypress(sender:
    tobject; var key: char);
    procedure akeydown(sender:
    tobject; var key: word; shift:
    tshiftstate);
    procedure clearhits(itemindex: integer);
    procedure addhits(itemindex:
    integer; hits: array of string);
    function editor(index: integer):
    tdbcombobox;
    { public declarations }
    published
    property leftlimit: integer read
    fleft write fleft default 10;
    property toplimit: integer read
    ftop write ftop default 10;
    property editorlen: integer read
    maxtextlen write maxtextlen;
    property labellen: integer read
    maxlabellen write maxlabellen    default 100;
    property lineheight: integer read
    flineheight write flineheight    default 15;
    property onokclick: tnotifyevent
    read fclick write fclick;
    property datasource: tdatasource
    read fdatasource write    fdatasource;
 file://数据源
    property columns: integer read
    fcolumns write fcolumns;//- >表列数
    { published declarations }
  end;
procedure Register;

type
TYNSearch = class(TCustomComboBox)
private
FDataSet: TDataSet; // 数据集
FListDataSet: TDataSet; // 下拉数据集
FDataField: string;
FDataFieldCN: string;
FListFields: string; // f1,f2
FListFieldsCN: string; // f1,f2
FPanelWidth: integer;
FPanelHeight: integer;
procedure DropDown(Sender: TObject);
procedure Change(Sender: TObject);
procedure Filter;
procedure AdjustDropDownForm(AControl: TControl; HostControl: TControl);
protected
public
constructor Create(Owner: TComponent); override;
published
property DataSet: TDataSet read FDataSet write FDataSet;
property ListDataSet: TDataSet read FListDataSet write FListDataSet;
property DataField: string read FDataField write FDataField;
property DataFieldCN: string read FDataFieldCN write FDataFieldCN;
property ListFields: string read FListFields write FListFields;
property ListFieldsCN: string read FListFieldsCN write FListFieldsCN;
property PanelWidth: Integer read FPanelWidth write FPanelWidth default 380;
property PanelHeight: Integer read FPanelHeight write FPanelHeight default 150;
end;

{ 为第i字段增加提示信息的方法}
procedure tdbpanel.addhits(itemindex:
integer; hits: array of string);
var
  m,n,i: integer;
begin
  n := length(editors);
  m := length(hits);
  if itemindex< n then begin
    for i:=0 to m-1 do editors[itemindex].items.add(hits[i]);
  end;
end;

procedure TYNSearch.Filter;
var
v: string;
ls: TStringList;
i: Integer;
begin
v := quotedstr('%' + Self.Text + '%');
PopupPanel.CDS.Filtered := False;
ls := TStringList.Create;
try
ls.Delimiter := ',';
ls.DelimitedText := Self.ListFields;
for i := 0 to ls.Count - 1 do
begin
if PopupPanel.CDS.Filter = '' then
begin
PopupPanel.CDS.Filter := ls[i] + ' like ' + v;
end
else
begin
PopupPanel.CDS.Filter := PopupPanel.CDS.Filter + ' or ' + ls[i] + ' like ' + v;
end;
end;
finally
ls.Free;
end;
PopupPanel.CDS.Filtered := True;
end;

constructor tdbpanel.create(aowner: tcomponent);
begin
  inherited create(aowner);
  fleft :=10;
  ftop := 10;
  maxtextlen := 100;
  maxlabellen := 100;
  flineheight := 15;
end;

constructor TPopupPanel.create(owner: TComponent);
begin
inherited;
Self.BevelOuter := bvnone;
self.Caption := '';
self.Width := Self.panelwidth;
self.Height := Self.panelheight;

http://www.bkjia.com/Delphijc/531076.htmlwww.bkjia.comtruehttp://www.bkjia.com/Delphijc/531076.htmlTechArticleunit DBPanel; interface uses windows, messages, sysutils, classes,graphics, controls, forms, dialogs, extctrls, dbctrls, stdctrls, db; type TDBPanel = class(tpanel) private { priva...

procedure TPopupPanel.createcols;
var
en, cn: TStringList;
i, k: integer;
begin
en := TStringList.Create;
cn := TStringList.Create;
try
en.Delimiter := ',';
en.DelimitedText := listfields;
cn.Delimiter := ',';
cn.DelimitedText := listfieldscn;
for i := 0 to Grid.Columns.Count - 1 do
begin
for k := 0 to en.Count - 1 do
begin
if Grid.Columns[i].FieldName = en[k] then
begin
Grid.Columns[i].Title.Caption := cn[k];
end
else
begin
Grid.Columns[i].Visible := False;
end;
end;
end;
finally
en.Free;
cn.Free;
end;
end;

procedure tdbpanel.akeypress(sender: tobject; var key: char);
begin
  if (sender is tdbcombobox) then begin
if key=#13 then (owner as tform).perform(wm_nextdlgctl, 0, 0);
  end;
end;

end;

uses
  windows, messages, sysutils, classes,graphics, controls, forms, dialogs,
  extctrls, dbctrls, stdctrls, db;

procedure TPopupPanel.griddblclick(sender: TObject);
begin
if Self.dataset <> nil then
begin
self.dataset.Edit;
self.dataset.FieldByName(self.datafield).Text := Self.CDS.fieldbyname(Self.datafield).Text;
Self.dataset.Post;
end;

procedure tdbpanel.akeydown
(sender: tobject; var key: word;
  shift: tshiftstate);
begin
  if (sender is tdbcombobox) then begin
    case key of
      vk_next: (sender as tdbcombobox)
      .datasource.dataset.next;
      vk_prior: (sender as tdbcombobox)
      .datasource.dataset.prior;
    end;
  end;
end;

end.

procedure tdbpanel.clearhits(itemindex: integer);
var
  n: integer;
begin
  n := length(editors);
  if itemindex< n then editors[itemindex].items.clear;
end;

interface

unit DBPanel;

if (AControl.Top + AControl.Height > WorkArea.Bottom) then
begin
AControl.Height := WorkArea.Bottom - AControl.Top;
end;

 

CDS := TClientDataSet.Create(Self);
DSP := TDataSetProvider.Create(self);
DS := TDataSource.Create(self);
DSP.DataSet := listdataset;
DS.DataSet := CDS;
CDS.Data := DSP.Data;

procedure TYNSearch.Change(Sender: TObject);
begin
if PopupPanel = nil then
begin
PopupPanel := TPopupPanel.create(self);
if self.DataSet <> nil then
PopupPanel.dataset := Self.DataSet;
PopupPanel.listdataset := self.ListDataSet;
PopupPanel.datafield := self.DataField;
PopupPanel.datafieldcn := self.DataFieldCN;
PopupPanel.listfields := self.ListFields;
PopupPanel.listfieldscn := self.ListFieldsCN;
PopupPanel.panelwidth := Self.PanelWidth;
PopupPanel.panelheight := self.PanelHeight;
PopupPanel.search := Integer(self);

Grid := TDBGrid.Create(Self);
Grid.Align := alClient;
Grid.DataSource := DS;
grid.ReadOnly := True;
Grid.Options := Grid.Options + [dgRowSelect];
grid.OnDblClick := griddblclick;

本文由宝马娱乐在线城发布于互联网络,转载请注明出处:宝马娱乐在线城下拉选择框

关键词: