adbtplds.pas

来自「delphi编程控件」· PAS 代码 · 共 109 行

PAS
109
字号
unit adbtplds;
(*
 COPYRIGHT (c) RSD Software 1997 - 98
 All Rights Reserved.
*)

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, DB, adbtempl;

type
  TFRepositoryDataSetAdd = class(TForm)
    LForm: TLabel;
    ComboBox: TComboBox;
    ListBox: TListBox;
    BOk: TButton;
    BCancel: TButton;
    BHelp: TButton;
    procedure ComboBoxClick(Sender: TObject);
    procedure ListBoxDblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    List : TList;
  end;

function GetNewAutoDefDataSet(ARepository : TAutoRepository) : TDataSet;

implementation
uses autostrs, audbstrs;
{$R *.DFM}

function GetNewAutoDefDataSet(ARepository : TAutoRepository) : TDataSet;
Var
  List : TList;

  procedure GetDataSets(AComponent : TComponent);
  Var
     i : Integer;
  begin
    if(AComponent <> Nil) then begin
      for i := 0 to AComponent.ComponentCount - 1 do begin
        if(AComponent.Components[i] is TDataSet)
        And (AComponent.Components[i].Name <> '')
        And(ARepository.DefDataSets.GetDefDataSet(TDataSet(AComponent.Components[i])) = Nil) then
          List.Add(AComponent.Components[i]);
//        else GetDataSets(AComponent.Components[i]);
      end;
    end;
  end;

Var
  AForm : TFRepositoryDataSetAdd;
  i : Integer;
begin
  Result := Nil;
  List := TList.Create;
  for i := 0 to Screen.FormCount - 1 do
    GetDataSets(Screen.Forms[i]);
  for i := 0 to Screen.DataModuleCount - 1 do
    GetDataSets(Screen.DataModules[i]);
  if(List.Count = 0) then begin
    List.Free;
    ShowMessage(LoadStr(ACDB_REPOSNODATASET));
    exit;
  end;
  AForm := TFRepositoryDataSetAdd.Create(Nil);
  for i := 0 to List.Count - 1 do
    if(AForm.ComboBox.Items.IndexOf(TComponent(List[i]).Owner.Name) = -1) then
      AForm.ComboBox.Items.AddObject(TComponent(List[i]).Owner.Name, TComponent(List[i]).Owner);
  AForm.List := List;
  AForm.ComboBox.ItemIndex := 0;
  AForm.ComboBoxClick(Nil);

  AForm.ShowModal;
  if(AForm.ModalResult = mrOk) then
    Result := TDataSet(AForm.ListBox.Items.Objects[AForm.ListBox.ItemIndex]);
  List.Free;
  AForm.Free;
end;

procedure TFRepositoryDataSetAdd.ComboBoxClick(Sender: TObject);
Var
  i : Integer;
begin
  ListBox.Items.Clear;
  for i := 0 to List.Count - 1 do
    if(TComponent(List[i]).Owner = TComponent(ComboBox.Items.Objects[ComboBox.ItemIndex])) then
      ListBox.Items.AddObject(TComponent(List[i]).Name, TComponent(List[i]));
  ListBox.ItemIndex := 0;    
end;

procedure TFRepositoryDataSetAdd.ListBoxDblClick(Sender: TObject);
begin
  ModalResult := mrOk;
end;

procedure TFRepositoryDataSetAdd.FormCreate(Sender: TObject);
begin
  Caption := LoadStr(ACDB_ADDDATASET);
  BOK.Caption := LoadStr(ACB_OK);
  BCancel.Caption := LoadStr(ACB_CANCEL);
  BHelp.Caption := LoadStr(ACB_HELP);
  LForm.Caption := LoadStr(ACDB_FORM);
end;

end.

⌨️ 快捷键说明

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