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) 2015 Tony Whyman, MWA Software |
19 |
+ |
* (http://www.mwasoftware.co.uk). |
20 |
+ |
* |
21 |
+ |
* All Rights Reserved. |
22 |
+ |
* |
23 |
+ |
* Contributor(s): ______________________________________. |
24 |
+ |
* |
25 |
+ |
*) |
26 |
+ |
|
27 |
|
unit Unit1; |
28 |
|
|
29 |
|
{$mode objfpc}{$H+} |
147 |
|
IBTransaction1: TIBTransaction; |
148 |
|
procedure DBImage1DBImageRead(Sender: TObject; S: TStream; |
149 |
|
var GraphExt: string); |
124 |
– |
procedure EmployeesAfterPost(DataSet: TDataSet); |
150 |
|
procedure EmployeesValidatePost(Sender: TObject; var CancelPost: boolean); |
151 |
|
procedure IBDatabase1AfterConnect(Sender: TObject); |
152 |
|
procedure IBLocalDBSupport1GetDBVersionNo(Sender: TObject; |
189 |
|
{ private declarations } |
190 |
|
FDirty: boolean; |
191 |
|
FNoAutoReopen: boolean; |
192 |
+ |
procedure DoDBOpen(Data: PtrInt); |
193 |
|
procedure Reopen(Data: PtrInt); |
194 |
|
function GetDBVersionNo: integer; |
195 |
|
public |
198 |
|
end; |
199 |
|
|
200 |
|
var |
201 |
< |
Form1: TForm1; |
201 |
> |
Form1: TForm1; |
202 |
|
|
203 |
|
implementation |
204 |
|
|
205 |
|
{$R *.lfm} |
206 |
|
|
207 |
< |
uses IB, Unit2; |
207 |
> |
uses IB, Unit2, IBMessages; |
208 |
|
|
209 |
|
const |
210 |
|
sNoName = '<no name>'; |
211 |
|
|
186 |
– |
function ExtractDBException(msg: string): string; |
187 |
– |
var Lines: TStringList; |
188 |
– |
begin |
189 |
– |
Lines := TStringList.Create; |
190 |
– |
try |
191 |
– |
Lines.Text := msg; |
192 |
– |
if pos('exception',Lines[0]) = 1 then |
193 |
– |
Result := Lines[2] |
194 |
– |
else |
195 |
– |
Result := msg |
196 |
– |
finally |
197 |
– |
Lines.Free |
198 |
– |
end; |
199 |
– |
end; |
200 |
– |
|
212 |
|
{ TForm1 } |
213 |
|
|
214 |
|
procedure TForm1.EmployeesSALARYGetText(Sender: TField; var aText: string; |
241 |
|
(Sender as TAction).Enabled := FDirty |
242 |
|
end; |
243 |
|
|
244 |
+ |
procedure TForm1.DoDBOpen(Data: PtrInt); |
245 |
+ |
begin |
246 |
+ |
try |
247 |
+ |
IBDatabase1.Connected := true; |
248 |
+ |
except On E:Exception do |
249 |
+ |
begin |
250 |
+ |
MessageDlg(E.Message,mtError,[mbOK],0); |
251 |
+ |
Close; |
252 |
+ |
Exit |
253 |
+ |
end; |
254 |
+ |
end; |
255 |
+ |
|
256 |
+ |
{If upgrade failed or downgrade not pending then exit} |
257 |
+ |
with IBLocalDBSupport1 do |
258 |
+ |
if (CurrentDBVersionNo < RequiredVersionNo) or |
259 |
+ |
((CurrentDBVersionNo > RequiredVersionNo) and not DowngradePending) then |
260 |
+ |
Close; |
261 |
+ |
end; |
262 |
+ |
|
263 |
|
procedure TForm1.Reopen(Data: PtrInt); |
264 |
|
begin |
265 |
|
with IBTransaction1 do |
266 |
|
if not InTransaction then StartTransaction; |
237 |
– |
Countries.Active := true; |
267 |
|
Employees.Active := true; |
268 |
+ |
Countries.Active := true; |
269 |
|
JobCodes.Active := true; |
270 |
|
Depts.Active := true; |
271 |
|
end; |
330 |
|
end; |
331 |
|
end; |
332 |
|
|
303 |
– |
procedure TForm1.EmployeesAfterPost(DataSet: TDataSet); |
304 |
– |
begin |
305 |
– |
Employees.Refresh |
306 |
– |
end; |
307 |
– |
|
333 |
|
procedure TForm1.DBImage1DBImageRead(Sender: TObject; S: TStream; |
334 |
|
var GraphExt: string); |
335 |
|
begin |
532 |
|
|
533 |
|
procedure TForm1.FormShow(Sender: TObject); |
534 |
|
begin |
535 |
< |
try |
536 |
< |
IBDatabase1.Connected := true; |
537 |
< |
except On E:Exception do |
538 |
< |
begin |
514 |
< |
MessageDlg(E.Message,mtError,[mbOK],0); |
515 |
< |
Close; |
516 |
< |
Exit |
517 |
< |
end; |
518 |
< |
end; |
519 |
< |
|
520 |
< |
{If upgrade failed or downgrade not pending then exit} |
521 |
< |
with IBLocalDBSupport1 do |
522 |
< |
if (CurrentDBVersionNo < RequiredVersionNo) or |
523 |
< |
((CurrentDBVersionNo > RequiredVersionNo) and not DowngradePending) then |
524 |
< |
Close; |
535 |
> |
{Set IB Exceptions to only show text message - omit SQLCode and Engine Code} |
536 |
> |
IBDatabase1.FirebirdAPI.GetStatus.SetIBDataBaseErrorMessages([ShowIBMessage]); |
537 |
> |
Application.ExceptionDialog := aedOkMessageBox; |
538 |
> |
Application.QueueAsyncCall(@DoDBOpen,0); |
539 |
|
end; |
540 |
|
|
541 |
|
procedure TForm1.EmployeesAfterDelete(DataSet: TDataSet); |
555 |
|
begin |
556 |
|
if E is EIBError then |
557 |
|
begin |
558 |
< |
MessageDlg(ExtractDBException(EIBError(E).message),mtError,[mbOK],0); |
558 |
> |
MessageDlg(EIBError(E).message,mtError,[mbOK],0); |
559 |
|
DataSet.Cancel; |
560 |
|
DataAction := daAbort |
561 |
|
end; |