1 |
unit _BaseTemplate; |
2 |
|
3 |
interface |
4 |
|
5 |
uses |
6 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
7 |
Dialogs, ExtCtrls, StdCtrls, StrUtils, |
8 |
TypeDefs; |
9 |
|
10 |
type |
11 |
TNewConnectionEvent = procedure(ConnectionID: Integer) of object; |
12 |
TCheckCloseableEvent = function: Boolean of object; |
13 |
|
14 |
TForm_BaseTemplate = class(TForm) |
15 |
panel_connection: TPanel; |
16 |
label_connection: TLabel; |
17 |
combo_connection: TComboBox; |
18 |
panel_basecontent: TPanel; |
19 |
procedure FormClose(Sender: TObject; var Action: TCloseAction); |
20 |
procedure FormActivate(Sender: TObject); |
21 |
procedure combo_connectionChange(Sender: TObject); |
22 |
protected |
23 |
FOnNewConnection: TNewConnectionEvent; |
24 |
FOnCheckCloseable: TCheckCloseableEvent; |
25 |
FConnectionID: Integer; |
26 |
function GetToolCloseable: Boolean; |
27 |
public |
28 |
constructor Create(AOwner: TComponent); override; |
29 |
procedure UpdateConList; |
30 |
procedure SelectConnection(ConnectionID: Integer); |
31 |
published |
32 |
property OnNewConnection: TNewConnectionEvent read FOnNewConnection write FOnNewConnection; |
33 |
property OnCheckCloseable: TCheckCloseableEvent read FOnCheckCloseable write FOnCheckCloseable; |
34 |
property ConnectionID: Integer read FConnectionID; |
35 |
property Closeable: Boolean read GetToolCloseable; |
36 |
end; |
37 |
|
38 |
|
39 |
implementation |
40 |
{$R *.dfm} |
41 |
uses Main, ConnectionManager; |
42 |
|
43 |
|
44 |
procedure TForm_BaseTemplate.UpdateConList; |
45 |
var |
46 |
i: Integer; |
47 |
fn, datatype, boxstring: String; |
48 |
level: Integer; |
49 |
begin |
50 |
combo_connection.ItemIndex := -1; |
51 |
combo_connection.Items.Clear; |
52 |
if ConManager.Count > 0 then |
53 |
begin |
54 |
for i := 0 to ConManager.Count - 1 do |
55 |
begin |
56 |
level := ConManager.ConnectionByIndex[i].LevelNumber; |
57 |
fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName); |
58 |
if ConManager.ConnectionByIndex[i].Backend = DB_ONI then |
59 |
datatype := 'ONI-.dat: ' |
60 |
else if ConManager.ConnectionByIndex[i].Backend = DB_ADB then |
61 |
datatype := 'OUP-DB: ' |
62 |
else |
63 |
datatype := 'Unknown: '; |
64 |
boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ') [' + IntToStr(ConManager.ConnectionByIndex[i].ConnectionID) + ']'; |
65 |
combo_connection.Items.Add(boxstring); |
66 |
if ConManager.ConnectionByIndex[i].ConnectionID = FConnectionID then |
67 |
combo_connection.ItemIndex := combo_connection.Items.Count - 1; |
68 |
end; |
69 |
if combo_connection.ItemIndex = -1 then |
70 |
begin |
71 |
combo_connection.ItemIndex := 0; |
72 |
combo_connectionChange(Self); |
73 |
end; |
74 |
end |
75 |
else |
76 |
begin |
77 |
FConnectionID := 0; |
78 |
combo_connectionChange(Self); |
79 |
end; |
80 |
end; |
81 |
|
82 |
|
83 |
|
84 |
procedure TForm_BaseTemplate.combo_connectionChange(Sender: TObject); |
85 |
var |
86 |
name: String; |
87 |
begin |
88 |
if combo_connection.ItemIndex >= 0 then |
89 |
begin |
90 |
name := combo_connection.Items.Strings[combo_connection.ItemIndex]; |
91 |
FConnectionID := StrToInt(MidStr(name, Pos('[', name) + 1, Pos(']', name) - Pos('[', name) - 1)); |
92 |
end |
93 |
else |
94 |
FConnectionID := -1; |
95 |
if Assigned(FOnNewConnection) then |
96 |
FOnNewConnection(FConnectionID); |
97 |
end; |
98 |
|
99 |
|
100 |
procedure TForm_BaseTemplate.SelectConnection(ConnectionID: Integer); |
101 |
begin |
102 |
if FConnectionID <> ConnectionID then |
103 |
begin |
104 |
combo_connection.ItemIndex := ConManager.ConnectionIndexByID[ConnectionID]; |
105 |
combo_connectionChange(Self); |
106 |
end; |
107 |
end; |
108 |
|
109 |
|
110 |
function TForm_BaseTemplate.GetToolCloseable: Boolean; |
111 |
begin |
112 |
if Assigned(FOnCheckCloseable) then |
113 |
Result := FOnCheckCloseable |
114 |
else |
115 |
Result := True; |
116 |
end; |
117 |
|
118 |
|
119 |
constructor TForm_BaseTemplate.Create(AOwner: TComponent); |
120 |
begin |
121 |
inherited; |
122 |
Self.Width := 260; |
123 |
Self.Height := 300; |
124 |
FOnNewConnection := nil; |
125 |
FOnCheckCloseable := nil; |
126 |
FConnectionID := -1; |
127 |
end; |
128 |
|
129 |
procedure TForm_BaseTemplate.FormActivate(Sender: TObject); |
130 |
begin |
131 |
if panel_basecontent.CanFocus then |
132 |
panel_basecontent.SetFocus; |
133 |
end; |
134 |
|
135 |
procedure TForm_BaseTemplate.FormClose(Sender: TObject; var Action: TCloseAction); |
136 |
begin |
137 |
Action := caFree; |
138 |
end; |
139 |
|
140 |
|
141 |
end. |