|
| 1 | +unit uServidor; |
| 2 | + |
| 3 | +interface |
| 4 | + |
| 5 | +uses |
| 6 | + Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
| 7 | + Dialogs, WideStrings, StdCtrls, DB, SqlExpr, DBXInterBase, DBXDevartInterBase, |
| 8 | + ExtCtrls; |
| 9 | + |
| 10 | +type |
| 11 | + TformServidor = class(TForm) |
| 12 | + SQLConnection: TSQLConnection; |
| 13 | + lbNome: TLabel; |
| 14 | + SQLMonitor: TSQLMonitor; |
| 15 | + tmrClose: TTimer; |
| 16 | + procedure FormCreate(Sender: TObject); |
| 17 | + procedure SQLConnectionAfterDisconnect(Sender: TObject); |
| 18 | + procedure tmrCloseTimer(Sender: TObject); |
| 19 | + procedure SQLConnectionAfterConnect(Sender: TObject); |
| 20 | + private |
| 21 | + { Private declarations } |
| 22 | + public |
| 23 | + { Public declarations } |
| 24 | + end; |
| 25 | + |
| 26 | +var |
| 27 | + formServidor: TformServidor; |
| 28 | + |
| 29 | +implementation |
| 30 | + |
| 31 | +{$R *.dfm} |
| 32 | + |
| 33 | +procedure TformServidor.FormCreate(Sender: TObject); |
| 34 | +var |
| 35 | + nome, extensao, base: string; |
| 36 | +begin |
| 37 | + |
| 38 | + if SQLConnection.Connected then |
| 39 | + SQLConnection.Close; |
| 40 | + |
| 41 | +// { limpo os par�metros } |
| 42 | +// SQLConnection.Params.Clear; |
| 43 | + |
| 44 | + { nome do cliente } |
| 45 | + nome := ExtractFileName(ParamStr(0)); |
| 46 | + extensao := ExtractFileExt (ParamStr(0)); |
| 47 | + delete(nome, pos(extensao, nome), length(extensao)); |
| 48 | + nome := uppercase(nome); |
| 49 | + |
| 50 | +// { defino a conex�o } |
| 51 | +// SQLConnection.ConnectionName := nome; |
| 52 | + |
| 53 | + { mudo somente o nome da base } |
| 54 | + base := SQLConnection.Params.Values['DataBase']; |
| 55 | + base := StringReplace(base, 'BASE', nome, [rfReplaceAll, rfIgnoreCase]); |
| 56 | + SQLConnection.Params.Values['DataBase'] := base; |
| 57 | + |
| 58 | + { abro a conex�o } |
| 59 | +// SQLMonitor.Active := True; |
| 60 | + SQLConnection.Open; |
| 61 | + |
| 62 | +end; |
| 63 | + |
| 64 | + |
| 65 | +procedure TformServidor.SQLConnectionAfterConnect(Sender: TObject); |
| 66 | +begin |
| 67 | + tmrClose.Enabled := false; |
| 68 | + tmrClose.Enabled := true; |
| 69 | +end; |
| 70 | + |
| 71 | +procedure TformServidor.SQLConnectionAfterDisconnect(Sender: TObject); |
| 72 | +begin |
| 73 | + if SQLConnection.Connected then |
| 74 | + SQLConnection.Close; |
| 75 | +end; |
| 76 | + |
| 77 | +procedure TformServidor.tmrCloseTimer(Sender: TObject); |
| 78 | +begin |
| 79 | + close; |
| 80 | +end; |
| 81 | + |
| 82 | +end. |
0 commit comments