--- ibx/trunk/design/ibgeneratoreditor.pas 2011/02/18 16:26:16 6 +++ ibx/trunk/design/ibgeneratoreditor.pas 2012/08/05 18:28:19 7 @@ -1,3 +1,29 @@ +(* + * IBX For Lazarus (Firebird Express) + * + * The contents of this file are subject to the Initial Developer's + * Public License Version 1.0 (the "License"); you may not use this + * file except in compliance with the License. You may obtain a copy + * of the License here: + * + * http://www.firebirdsql.org/index.php?op=doc&id=idpl + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing rights + * and limitations under the License. + * + * The Initial Developer of the Original Code is Tony Whyman. + * + * The Original Code is (C) 2011 Tony Whyman, MWA Software + * (http://www.mwasoftware.co.uk). + * + * All Rights Reserved. + * + * Contributor(s): ______________________________________. + * +*) + unit IBGeneratorEditor; {$mode objfpc}{$H+} @@ -5,7 +31,7 @@ unit IBGeneratorEditor; interface uses - Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, ComCtrls, IBDatabase, IBCustomDataSet, IBSystemTables; type @@ -18,6 +44,7 @@ type Button2: TButton; GeneratorNames: TComboBox; FieldNames: TComboBox; + IBTransaction1: TIBTransaction; IncrementBy: TEdit; Label1: TLabel; Label2: TLabel; @@ -48,24 +75,28 @@ function EditGenerator(AGenerator: TIBGe implementation +uses IBQuery; + +{$R *.lfm} + function EditGenerator(AGenerator: TIBGenerator): boolean; var Database: TIBDatabase; begin Result := false; - if AGenerator.SelectSQL = '' then + if (AGenerator.Owner is TIBQuery and ((AGenerator.Owner as TIBQuery).SQL.Text = '')) or + (AGenerator.Owner is TIBDataSet and ((AGenerator.Owner as TIBDataSet).SelectSQL.Text = '')) then begin ShowMessage('No Select SQL Found!'); Exit end; + Database := AGenerator.Owner.Database; + if assigned(Database) then - begin - Database := AGenerator.Owner.Database; - if not assigned(AGenerator.Owner.Transaction)then - begin - ShowMessage('No Transaction assigned to DataSet!'); - Exit + try + Database.Connected := true; + except on E: Exception do + ShowMessage(E.Message) end; - Database.Connected := true; with TGeneratorEditor.Create(Application) do try @@ -74,7 +105,6 @@ begin finally Free end; - end; end; { TGeneratorEditor } @@ -83,13 +113,16 @@ procedure TGeneratorEditor.FormShow(Send begin LoadGenerators; LoadFieldNames; - if Generator.GeneratorName <> '' then - GeneratorNames.ItemIndex := GeneratorNames.Items.IndexOf(Generator.GeneratorName); - if Generator.FieldName <> '' then - FieldNames.ItemIndex := FieldNames.Items.IndexOf(Generator.FieldName) + if Generator.Generator <> '' then + GeneratorNames.ItemIndex := GeneratorNames.Items.IndexOf(Generator.Generator); + if Generator.Field <> '' then + FieldNames.ItemIndex := FieldNames.Items.IndexOf(UpperCase(Generator.Field)) else FieldNames.ItemIndex := FieldNames.Items.IndexOf(GetPrimaryKey); + if FieldNames.ItemIndex = -1 then + FieldNames.Text := Generator.Field; + if Generator.ApplyOnEvent = gaeOnNewRecord then OnNewRecord.Checked := true else @@ -102,8 +135,8 @@ procedure TGeneratorEditor.FormClose(Sen begin if ModalResult = mrOK then begin - Generator.GeneratorName := GeneratorNames.Text; - Generator.FieldName := FieldNames.Text; + Generator.Generator := GeneratorNames.Text; + Generator.Field := FieldNames.Text; if OnNewRecord.Checked then Generator.ApplyOnEvent := gaeOnNewRecord else @@ -122,7 +155,13 @@ end; procedure TGeneratorEditor.LoadFieldNames; begin - FIBSystemTables.GetTableAndColumns(FGenerator.SelectSQL,FTableName,FieldNames.Items) + if FGenerator.Owner is TIBDataSet then + FIBSystemTables.GetTableAndColumns((FGenerator.Owner as TIBDataSet).SelectSQL.Text,FTableName,FieldNames.Items) + else + if FGenerator.Owner is TIBQuery then + FIBSystemTables.GetTableAndColumns((FGenerator.Owner as TIBQuery).SQL.Text,FTableName,FieldNames.Items) + else + raise Exception.CreateFmt('Don''t know how to edit a %s',[FGenerator.Owner.ClassName]) end; function TGeneratorEditor.GetPrimaryKey: string; @@ -142,7 +181,8 @@ end; procedure TGeneratorEditor.SetGenerator(const AValue: TIBGenerator); begin FGenerator := AValue; - SetDatabase(Generator.Owner.Database,Generator.Owner.Transaction); + IBTransaction1.DefaultDatabase := Generator.Owner.Database; + SetDatabase(Generator.Owner.Database,IBTransaction1); end; procedure TGeneratorEditor.SetDatabase(ADatabase: TIBDatabase; ATransaction: TIBTransaction); @@ -166,8 +206,5 @@ begin inherited Destroy; end; -initialization - {$I ibgeneratoreditor.lrs} - end.