L3_pas
unit F_TbDef;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables, ExtCtrls, Buttons, ComCtrls, DbItfT, DbItf, MnT;
Type
TTbDefFr = class (TForm)
TbFieldsListBox: TListBox;
NewFieldButton: TButton;
OkButton: TButton;
CancelButton: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Bevel1: TBevel;
Label10: TLabel;
TbNameLbl: TLabel;
procedure NewFieldButtonClick(Sender: TObject);
procedure CancelButtonClick(Sender: TObject);
procedure OkButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TbFieldsListBoxClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
FModalRes : Boolean;
FpTTableInfo : pTTableInfo;
FDbInterface : TDbInterface;
FpTInfoCategory : pTInfoCategory;
procedure Set_FDbInterface(const Value: TDbInterface);
procedure Set_FpTInfoCategory(const Value: pTInfoCategory);
public
{ Public declarations }
Function Execute : Bool;
Property ppTTableInfo : pTTableInfo read FpTTableInfo write FpTTableInfo;
Property ppTInfoCategory : pTInfoCategory read FpTInfoCategory
write Set_FpTInfoCategory;
published
Property DbInterface : TDbInterface read FDbInterface write Set_FDbInterface;
end;
Var
TbDefFr: TTbDefFr;
implementation
uses
F_FldDlg;
{$R *.DFM}
procedure TTbDefFr.NewFieldButtonClick(Sender: TObject);
begin
if FldDlgFr = nil then
FldDlgFr := TFldDlgFr.Create(nil);
try
// Создаем новую структуру таблицы
FldDlgFr.DbInterface := FDbInterface;
FDbInterface.Init_NpTFieldInfo;
FDbInterface.Current_pTTableInfo := FDbInterface.N_pTTableInfo;
FldDlgFr.ShowModal;
if FldDlgFr.Execute then
begin { Структура заполнена успешно - сохранить ее }
TbFieldsListBox.Items.AddObject(
FDbInterface.N_pTFieldInfo.sFieldAttr.Values['sFieldCaption'],
Pointer(FDbInterface.N_pTFieldInfo));
FpTTableInfo.sFieldsL.Add(Pointer(FDbInterface.N_pTFieldInfo));
end
else { Структура не нужна - удалить из памяти }
FDbInterface.Kill_NpTFieldInfo;
finally
FreeAndNil(FldDlgFr);
end;
end;
// Завершение создания таблицы в БД
Function TTbDefFr.Execute: Bool;
Var
wTb : TTable;
begin
Result := False;
if not FModalRes then
Exit;
wTb := TTable.Create(nil);
wTb.DatabaseName := FDbInterface.DatabaseName;
try
wTb.TableName := 'T_Tables';
if not wTb.Exists then
Create_T_Tables(wTb);
wTb.TableName := 'T_Fields';
if not wTb.Exists then
Create_T_Fields(wTb);
finally
wTb.Free;
end;
FpTTableInfo.spTInfoCategory := FpTInfoCategory;
Result := FDbInterface.CreateFbTableBySQL(FpTTableInfo,
TbFieldsListBox.Items);
end;
procedure TTbDefFr.CancelButtonClick(Sender: TObject);
begin
FModalRes := False;
Close;
end;
procedure TTbDefFr.OkButtonClick(Sender: TObject);
begin
FModalRes := True;
Close;
end;
procedure TTbDefFr.FormCreate(Sender: TObject);
begin
Label4.Caption := '';
Label5.Caption := '';
Label7.Caption := '';
Label8.Caption := '';
TbNameLbl.Caption := '';
end;
// Вывод сведений о поле для наблюдения
procedure TTbDefFr.TbFieldsListBoxClick(Sender: TObject);
Var
k : Integer;
wpFldInfo : pTFieldInfo;
wTFieldType : TFieldType;
begin
Label4.Visible := False;
Label5.Visible := False;
Label7.Visible := False;
Label8.Visible := False;
if TbFieldsListBox.Items.Count = 0 then
Exit;
k := TbFieldsListBox.ItemIndex;
if TbFieldsListBox.Items.Objects[k] = nil then
Exit;
wpFldInfo := pTFieldInfo(TbFieldsListBox.Items.Objects[k]);
wTFieldType := wpFldInfo.sFieldType;
Label4.Caption := FDbInterface.FbFieldArray[wTFieldType].sDescr;
Label5.Caption := IntToStr(wpFldInfo.sFieldSize) +
'/' + IntToStr(wpFldInfo.sFieldMBytes);
Label7.Caption := wpFldInfo.sFieldAttr.Values['sFieldCaption'];
Label8.Caption := wpFldInfo.sFieldAttr.Values['sFieldDescr'];
Label4.Visible := Label4.Caption <> '';
Label5.Visible := Label5.Caption <> '';
Label7.Visible := Label7.Caption <> '';
Label8.Visible := Label8.Caption <> '';
Label2.Visible := Label4.Visible;
Label3.Visible := Label5.Visible;
Label6.Visible := Label7.Visible;
Label9.Visible := Label8.Visible;
end;
procedure TTbDefFr.Set_FDbInterface(const Value: TDbInterface);
begin
FDbInterface := Value;
end;
procedure TTbDefFr.Set_FpTInfoCategory(const Value: pTInfoCategory);
begin
FpTInfoCategory := Value;
apAutoID := True;
end;
procedure TTbDefFr.FormActivate(Sender: TObject);
Var
k : Integer;
wpTFieldInfo : pTFieldInfo;
begin
Label10.Show;
TbNameLbl.Caption := FpTTableInfo.sTableAttr.Values['sTableCaption'];
// ..прикрепить и показать имеющиеся поля
for k := 0 to FpTTableInfo.sFieldsL.Count - 1 do
begin
wpTFieldInfo := pTFieldInfo(FpTTableInfo.sFieldsL[k]);
TbFieldsListBox.Items.AddObject(
wpTFieldInfo.sFieldAttr.Values['sFieldCaption'],
Pointer(wpTFieldInfo));
end;
end;
end.