Author: Tomas Rutkauskas
I use a TCoolBar with several TToolbars and some other controls. During runtime a
user can automatically reorder and resize the bands on the TCoolbar, is there a
easy way of saving the positions and sizes of the different bands and reloading
them a next time?
Answer:
You have to save the ID, Break, Width and Index of the bands. Following is a
snippet of code that I use to save the Coolbar in the registry.
1 { ... }
2
3 var
4 RegristryFile: TRegIniFile;
5
6 const
7 Ident = 'ID';
8 Brk = 'Break';
9 Wdth = 'Width';
10 Ndx = 'Index';
11
12 { ... }
13
14 procedure SaveCoolBars;
15 var
16 A: Integer;
17 IdStr: string;
18 begin
19 with CoolBar, Bands do
20 begin
21 for A := 0 to Count - 1 do
22 with Bands[A] do
23 begin
24 IdStr := IntToStr(Id);
25 with RegristryFile do
26 begin
27 EraseSection(IdStr);
28 WriteBool(IdStr, Brk, Break);
29 WriteInteger(IdStr, Wdth, Width);
30 WriteInteger(IdStr, Ndx, Index);
31 end;
32 end;
33 end;
34 end;
35
36 procedure LoadCoolBars;
37 var
38 A: Integer;
39 B: TCoolBand;
40 IdStr: string;
41 begin
42 with CoolBar, Bands do
43 begin
44 for A := 0 to Count - 1 do
45 begin
46 B := TCoolband(Bands.FindItemID(A));
47 if B = nil then
48 Continue;
49 with B, RegristryFile do
50 begin
51 IdStr := IntToStr(Id);
52 Break := ReadBool(IdStr, Brk, Break);
53 Width := ReadInteger(IdStr, Wdth, Width);
54 Index := ReadInteger(IdStr, Ndx, Index);
55 end;
56 end;
57 end;
58 end;
|