forked from ibv/LDAP-Admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBLoad.pas
105 lines (92 loc) · 2.61 KB
/
DBLoad.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{ LDAPAdmin - DBLoad.pas
* Copyright (C) 2016 Tihomir Karlovic
*
* Author: Tihomir Karlovic
*
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
}
unit DBLoad;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
uses
{$IFnDEF FPC}
Windows,
{$ELSE}
LCLIntf, LCLType, LMessages,
{$ENDIF}
Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, Connection;
type
TDBLoadDlg = class(TForm)
CancelBtn: TButton;
Message: TLabel;
ProgressBar: TProgressBar;
PathLabel: TLabel;
procedure CancelBtnClick(Sender: TObject);
private
fAbort: Boolean;
fNumObjects: Integer;
fFileName: string;
procedure CallbackProc(BytesRead: Integer; var Abort: Boolean);
public
{ Public declarations }
end;
function LoadDB(Owner: TComponent; Account: TDBAccount): TConnection;
implementation
{$R *.dfm}
function LoadDB(Owner: TComponent; Account: TDBAccount): TConnection;
var
F: File;
ACursor: TCursor;
begin
Result := nil;
ACursor := Screen.Cursor;
with TDBLoadDlg.Create(Owner) do
try
Screen.Cursor := crAppStart;
Show;
fFileName := Account.FileName;
System.Assign(F, Account.FileName);
FileMode := 0;
Reset(F,1);
try
ProgressBar.Max := FileSize(F);
finally
CloseFile(F);
end;
Result := TDBConnection.Create(TDBAccount(Account), CallbackProc);
if fAbort then
FreeAndNil(Result);
finally
Screen.Cursor := ACursor;
Free;
end;
end;
procedure TDBLoadDlg.CallbackProc(BytesRead: Integer; var Abort: Boolean);
begin
Abort := fAbort;
inc(fNumObjects);
Message.Caption := Format('Parsing file %s: %d objects loaded', [fFileName, fNumObjects]);
ProgressBar.Position := BytesRead;
Application.ProcessMessages;
end;
procedure TDBLoadDlg.CancelBtnClick(Sender: TObject);
begin
fAbort := true;
end;
end.