adbtplcn.pas
来自「delphi编程控件」· PAS 代码 · 共 216 行
PAS
216 行
unit adbtplcn;
(*
COPYRIGHT (c) RSD Software 1997 - 98
All Rights Reserved.
*)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, adbtempl;
type
TFAutoRepositoryDefControls = class(TForm)
ListBox: TListBox;
BAdd: TButton;
BDelete: TButton;
BHelp: TButton;
GB: TGroupBox;
CheckBox1: TCheckBox;
ListBox1: TListBox;
BOk: TButton;
BCancel: TButton;
BClose: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure ListBoxClick(Sender: TObject);
procedure BAddClick(Sender: TObject);
procedure BDeleteClick(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure BCloseClick(Sender: TObject);
private
Repository : TAutoRepository;
procedure FillList;
procedure ComponentNameChanged(Sender : TObject);
end;
function SelectAutoDBDefControl(AOwner : TComponent) : TAutoDBDefControl;
implementation
uses Dsgnintf, TypInfo, adbtmple, adbtlcad, autostrs, audbstrs;
{$R *.DFM}
{$I aclver.inc}
function SelectAutoDBDefControl(AOwner : TComponent) : TAutoDBDefControl;
Var
AForm : TFAutoRepositoryDefControls;
i : Integer;
begin
Result := Nil;
AForm := TFAutoRepositoryDefControls.Create(AOwner);
with AForm do begin
BorderStyle := bsDialog;
BOk.Visible := True;
BCancel.Visible := True;
BDelete.Visible := False;
BClose.Visible := False;
BAdd.Left := 2*AForm.BCancel.Left - AForm.BOk.Left;
BOk.TabOrder := 2;
BCancel.TabOrder := 3;
CheckBox1Click(Nil);
ShowModal;
end;
if(AForm.ModalResult = mrOk) then
Result := TAutoDBDefControl(AForm.ListBox.Items.Objects[AForm.ListBox.ItemIndex]);
if(AForm.Repository <> Nil) And Not (csDestroying in AForm.Repository.ComponentState) then
for i := 0 to AForm.Repository.DBDefControlCount - 1 do
AForm.Repository.DBDefControls[i].OnChangeName := Nil;
AForm.Free;
end;
procedure TFAutoRepositoryDefControls.FillList;
Var
i : Integer;
p : Pointer;
begin
if (ListBox.ItemIndex > -1) and (ListBox.ItemIndex < ListBox.Items.Count) then
p := ListBox.Items.Objects[ListBox.ItemIndex]
else p := Nil;
ListBox.Items.Clear;
for i := 0 to Repository.DBDefControlCount - 1 do
if (Repository.DBDefControls[i].DBDefControlType <> adctUnknown)
And (ListBox1.Selected[Integer(Repository.DBDefControls[i].DBDefControlType) - 1]) then
begin
ListBox.Items.AddObject(Repository.DBDefControls[i].Name, Repository.DBDefControls[i]);
Repository.DBDefControls[i].OnChangeName := ComponentNameChanged;
end;
if(p <> Nil) then
for i := 0 to ListBox.Items.Count - 1 do
if(ListBox.Items.Objects[i] = p) then begin
ListBox.ItemIndex := i;
break;
end;
if(ListBox.ItemIndex = -1) And (ListBox.Items.Count > -1) then
ListBox.ItemIndex := 0;
if Not BOk.Visible then
BDelete.Enabled := ListBox.Items.Count > 0
else BOk.Enabled := ListBox.Items.Count > 0;
ListBoxClick(Nil);
end;
procedure TFAutoRepositoryDefControls.ComponentNameChanged(Sender : TObject);
Var
i, Index : Integer;
begin
for i := 0 to ListBox.Items.Count - 1 do
if(TAutoDBDefControl(ListBox.Items.Objects[i]) = TAutoDBDefControl(Sender)) then
break;
if(i > -1) And (i < ListBox.Items.Count) then begin
Index := ListBox.ItemIndex;
ListBox.Items[i] := TComponent(Sender).Name;
if(Index > -1) then
ListBox.ItemIndex := Index;
end;
end;
procedure TFAutoRepositoryDefControls.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
if Not BOk.Visible then
TFAutoRepositoryEditor(Owner).DefControlsForm := Nil;
end;
type
TDummyAutoDBDefControl = class(TAutoDBDefControl)
published
property DBDefControlType;
end;
procedure TFAutoRepositoryDefControls.FormCreate(Sender: TObject);
Var
i : Integer;
pInfo : PPropInfo;
St : String;
begin
Repository := TFAutoRepositoryEditor(Owner).Repository;
pInfo := GetPropInfo(TDummyAutoDBDefControl.ClassInfo, 'DBDefControlType');
if (pInfo <> Nil) And (pInfo^.PropType^.Kind = tkEnumeration) then begin
i := 1;
St := GetEnumName(pInfo^.PropType{$IFDEF DELPHI3_0}^{$ENDIF}, i);
while Pos('adct', St) > 0 do begin
ListBox1.Items.Add(St);
Inc(i);
St := GetEnumName(pInfo^.PropType{$IFDEF DELPHI3_0}^{$ENDIF}, i);
end;
end;
for i := 0 to ListBox1.Items.Count - 1 do
ListBox1.Selected[i] := True;
FillList;
BOK.Caption := LoadStr(ACB_OK);
BCancel.Caption := LoadStr(ACB_CANCEL);
BAdd.Caption := LoadStr(ACB_ADDEX);
BDelete.Caption := LoadStr(ACB_DELETE);
BClose.Caption := LoadStr(ACB_CLOSE);
BHelp.Caption := LoadStr(ACB_HELP);
CheckBox1.Caption := LoadStr(ACDB_ALLTYPES);
GB.Caption := LoadStr(ACDB_DBDEFCONTROLTYPE);
Caption := LoadStr(ACDB_DBDEFCONTROL);
end;
procedure TFAutoRepositoryDefControls.ListBoxClick(Sender: TObject);
begin
if(ListBox.ItemIndex > -1) And (Repository.Designer <> Nil) then
{$IFDEF DELPHI4}IFormDesigner{$ELSE}TFormDesigner{$ENDIF}(Repository.Designer).SelectComponent(
TComponent(ListBox.Items.Objects[ListBox.ItemIndex]));
end;
procedure TFAutoRepositoryDefControls.BAddClick(Sender: TObject);
begin
CreateAutoDBDefControl(Repository);
FillList;
end;
procedure TFAutoRepositoryDefControls.BDeleteClick(Sender: TObject);
Var
Index : Integer;
begin
if(ListBox.ItemIndex > -1) then begin
Index := ListBox.ItemIndex;
if(Index = ListBox.Items.Count - 1) then Dec(Index);
TAutoDBDefControl(ListBox.Items.Objects[ListBox.ItemIndex]).Free;
FillList;
if(ListBox.Items.Count > 1) then begin
if(Index = ListBox.Items.Count) then Dec(Index);
ListBox.ItemIndex := Index;
end;
end;
end;
procedure TFAutoRepositoryDefControls.CheckBox1Click(Sender: TObject);
Var
i : Integer;
begin
if(CheckBox1.Checked) then
for i := 0 to ListBox1.Items.Count - 1 do
ListBox1.Selected[i] := True;
FillList;
end;
procedure TFAutoRepositoryDefControls.ListBox1Click(Sender: TObject);
begin
CheckBox1.Checked := False;
CheckBox1Click(Sender);
end;
procedure TFAutoRepositoryDefControls.BCloseClick(Sender: TObject);
begin
Close;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?