source: oup/current/Tools/_BaseTemplate.pas@ 1110

Last change on this file since 1110 was 218, checked in by alloc, 17 years ago
File size: 3.9 KB
RevLine 
[217]1unit _BaseTemplate;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, ExtCtrls, StdCtrls, StrUtils,
8 TypeDefs;
9
10type
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
39implementation
40{$R *.dfm}
41uses Main, ConnectionManager;
42
43
44procedure TForm_BaseTemplate.UpdateConList;
45var
46 i: Integer;
47 fn, datatype, boxstring: String;
48 level: Integer;
49begin
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;
80end;
81
82
83
84procedure TForm_BaseTemplate.combo_connectionChange(Sender: TObject);
85var
86 name: String;
87begin
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);
97end;
98
99
100procedure TForm_BaseTemplate.SelectConnection(ConnectionID: Integer);
101begin
102 if FConnectionID <> ConnectionID then
103 begin
104 combo_connection.ItemIndex := ConManager.ConnectionIndexByID[ConnectionID];
105 combo_connectionChange(Self);
106 end;
107end;
108
109
110function TForm_BaseTemplate.GetToolCloseable: Boolean;
111begin
112 if Assigned(FOnCheckCloseable) then
113 Result := FOnCheckCloseable
114 else
115 Result := True;
116end;
117
118
119constructor TForm_BaseTemplate.Create(AOwner: TComponent);
120begin
121 inherited;
122 Self.Width := 260;
123 Self.Height := 300;
124 FOnNewConnection := nil;
125 FOnCheckCloseable := nil;
126 FConnectionID := -1;
127end;
128
129procedure TForm_BaseTemplate.FormActivate(Sender: TObject);
130begin
131 if panel_basecontent.CanFocus then
132 panel_basecontent.SetFocus;
133end;
134
135procedure TForm_BaseTemplate.FormClose(Sender: TObject; var Action: TCloseAction);
136begin
137 Action := caFree;
138end;
139
140
141end.
Note: See TracBrowser for help on using the repository browser.