ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/design/ibgeneratoreditor.pas
(Generate patch)

Comparing ibx/trunk/design/ibgeneratoreditor.pas (file contents):
Revision 5 by tony, Fri Feb 18 16:26:16 2011 UTC vs.
Revision 7 by tony, Sun Aug 5 18:28:19 2012 UTC

# Line 1 | Line 1
1 + (*
2 + *  IBX For Lazarus (Firebird Express)
3 + *
4 + *  The contents of this file are subject to the Initial Developer's
5 + *  Public License Version 1.0 (the "License"); you may not use this
6 + *  file except in compliance with the License. You may obtain a copy
7 + *  of the License here:
8 + *
9 + *    http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 + *
11 + *  Software distributed under the License is distributed on an "AS
12 + *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
13 + *  implied. See the License for the specific language governing rights
14 + *  and limitations under the License.
15 + *
16 + *  The Initial Developer of the Original Code is Tony Whyman.
17 + *
18 + *  The Original Code is (C) 2011 Tony Whyman, MWA Software
19 + *  (http://www.mwasoftware.co.uk).
20 + *
21 + *  All Rights Reserved.
22 + *
23 + *  Contributor(s): ______________________________________.
24 + *
25 + *)
26 +
27   unit IBGeneratorEditor;
28  
29   {$mode objfpc}{$H+}
# Line 5 | Line 31 | unit IBGeneratorEditor;
31   interface
32  
33   uses
34 <  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
34 >  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
35    ExtCtrls, StdCtrls, ComCtrls, IBDatabase, IBCustomDataSet, IBSystemTables;
36  
37   type
# Line 18 | Line 44 | type
44      Button2: TButton;
45      GeneratorNames: TComboBox;
46      FieldNames: TComboBox;
47 +    IBTransaction1: TIBTransaction;
48      IncrementBy: TEdit;
49      Label1: TLabel;
50      Label2: TLabel;
# Line 48 | Line 75 | function EditGenerator(AGenerator: TIBGe
75  
76   implementation
77  
78 + uses IBQuery;
79 +
80 + {$R *.lfm}
81 +
82   function EditGenerator(AGenerator: TIBGenerator): boolean;
83   var Database: TIBDatabase;
84   begin
85    Result := false;
86 <  if AGenerator.SelectSQL = '' then
86 >  if (AGenerator.Owner is TIBQuery and ((AGenerator.Owner as TIBQuery).SQL.Text = '')) or
87 >   (AGenerator.Owner is TIBDataSet and ((AGenerator.Owner as TIBDataSet).SelectSQL.Text = '')) then
88    begin
89      ShowMessage('No Select SQL Found!');
90      Exit
91    end;
92 +  Database := AGenerator.Owner.Database;
93 +
94    if assigned(Database) then
95 <  begin
96 <    Database := AGenerator.Owner.Database;
97 <    if not assigned(AGenerator.Owner.Transaction)then
98 <    begin
65 <      ShowMessage('No Transaction assigned to DataSet!');
66 <      Exit
95 >    try
96 >      Database.Connected := true;
97 >    except on E: Exception do
98 >      ShowMessage(E.Message)
99      end;
68    Database.Connected := true;
100  
101      with TGeneratorEditor.Create(Application) do
102      try
# Line 74 | Line 105 | begin
105      finally
106        Free
107      end;
77  end;
108   end;
109  
110   { TGeneratorEditor }
# Line 83 | Line 113 | procedure TGeneratorEditor.FormShow(Send
113   begin
114    LoadGenerators;
115    LoadFieldNames;
116 <  if Generator.GeneratorName <> '' then
117 <    GeneratorNames.ItemIndex := GeneratorNames.Items.IndexOf(Generator.GeneratorName);
118 <  if Generator.FieldName <> '' then
119 <    FieldNames.ItemIndex := FieldNames.Items.IndexOf(Generator.FieldName)
116 >  if Generator.Generator <> '' then
117 >    GeneratorNames.ItemIndex := GeneratorNames.Items.IndexOf(Generator.Generator);
118 >  if Generator.Field <> '' then
119 >    FieldNames.ItemIndex := FieldNames.Items.IndexOf(UpperCase(Generator.Field))
120    else
121      FieldNames.ItemIndex := FieldNames.Items.IndexOf(GetPrimaryKey);
122  
123 +  if FieldNames.ItemIndex = -1 then
124 +    FieldNames.Text := Generator.Field;
125 +
126    if Generator.ApplyOnEvent = gaeOnNewRecord then
127      OnNewRecord.Checked := true
128    else
# Line 102 | Line 135 | procedure TGeneratorEditor.FormClose(Sen
135   begin
136    if ModalResult = mrOK then
137    begin
138 <    Generator.GeneratorName := GeneratorNames.Text;
139 <    Generator.FieldName := FieldNames.Text;
138 >    Generator.Generator := GeneratorNames.Text;
139 >    Generator.Field := FieldNames.Text;
140      if OnNewRecord.Checked then
141        Generator.ApplyOnEvent := gaeOnNewRecord
142      else
# Line 122 | Line 155 | end;
155  
156   procedure TGeneratorEditor.LoadFieldNames;
157   begin
158 <  FIBSystemTables.GetTableAndColumns(FGenerator.SelectSQL,FTableName,FieldNames.Items)
158 >  if FGenerator.Owner is TIBDataSet then
159 >    FIBSystemTables.GetTableAndColumns((FGenerator.Owner as TIBDataSet).SelectSQL.Text,FTableName,FieldNames.Items)
160 >  else
161 >  if FGenerator.Owner is TIBQuery then
162 >    FIBSystemTables.GetTableAndColumns((FGenerator.Owner as TIBQuery).SQL.Text,FTableName,FieldNames.Items)
163 >  else
164 >    raise Exception.CreateFmt('Don''t know how to edit a %s',[FGenerator.Owner.ClassName])
165   end;
166  
167   function TGeneratorEditor.GetPrimaryKey: string;
# Line 142 | Line 181 | end;
181   procedure TGeneratorEditor.SetGenerator(const AValue: TIBGenerator);
182   begin
183    FGenerator := AValue;
184 <  SetDatabase(Generator.Owner.Database,Generator.Owner.Transaction);
184 >  IBTransaction1.DefaultDatabase := Generator.Owner.Database;
185 >  SetDatabase(Generator.Owner.Database,IBTransaction1);
186   end;
187  
188   procedure TGeneratorEditor.SetDatabase(ADatabase: TIBDatabase; ATransaction: TIBTransaction);
# Line 166 | Line 206 | begin
206    inherited Destroy;
207   end;
208  
169 initialization
170  {$I ibgeneratoreditor.lrs}
171
209   end.
210  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines