TSelect

 

unit uSelect;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FindDM, Grids, DBGrids, ExtCtrls, StdCtrls, Buttons, DB;

type
  TSelect = class(TForm)
    TFindFrames1: TFindFrames;
    DBGrid1: TDBGrid;
    Panel1: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    DataSource1: TDataSource;
  private
    { Private declarations }
  public
    { Public declarations }
    FDataSet: TDataSet;
  end;

procedure Execute(DataSet: TDataSet);

var
  Select: TSelect;

implementation

{$R *.dfm}

procedure AdjustDropDownForm(AControl: TControl);  //设置下拉窗口位置。
var
  WorkArea: TRect;
  HostP, PDelpta: TPoint;
begin
  SystemParametersInfo(SPI_GETWORKAREA, 0, @WorkArea, 0);
  GetCursorPos(HostP); //根据点击的鼠标位置决定显示的位置
  PDelpta := AControl.ClientToScreen(Point(0, 0));
  AControl.Left := HostP.x - 2;
  AControl.Top := HostP.y - 3;
  if (AControl.Width > WorkArea.Right - WorkArea.Left) then
    AControl.Width := WorkArea.Right - WorkArea.Left;
  if (AControl.Left + AControl.Width > WorkArea.Right) then
    AControl.Left := WorkArea.Right - AControl.Width;
  if (AControl.Left < WorkArea.Left) then
    AControl.Left := WorkArea.Left;
  if (AControl.Top + AControl.Height > WorkArea.Bottom) then
  begin
    if (HostP.y - WorkArea.Top > WorkArea.Bottom - HostP.y ) then
      AControl.Top := HostP.y - AControl.Height;
  end;
  if (AControl.Top < WorkArea.Top) then
  begin
    AControl.Height := AControl.Height - (WorkArea.Top - AControl.Top);
    AControl.Top := WorkArea.Top;
  end;
  if (AControl.Top + AControl.Height > WorkArea.Bottom) then
  begin
    AControl.Height := WorkArea.Bottom - AControl.Top;
  end;
end;

procedure Execute(DataSet: TDataSet);
begin
  if DataSet = nil then Exit;
  if DataSet.IsEmpty then Exit;
  Select := TSelect.Create(Application);
  Select.FDataSet := DataSet;
  Select.DataSource1.DataSet := Select.FDataSet;
  Select.TFindFrames1.DataSet := Select.FDataSet;
  AdjustDropDownForm(Select);
  try
    Select.ShowModal;
  finally
    FreeAndNil(Select);
  end;
end;

end.

你可能感兴趣的:(select)