Author: Eber Irigoyen
When we use StringGrid many times have a hard time initializing the columns, and
the widths, etc...
Answer:
here's my approach to this issue, as I use a lot of stringgrids to create reports
or show information... so I ended up creating this function to initialize its
headers and stuff
1
2 procedure InitGridFromINI(StrGrid: TStringGrid; const Section: string; GridINI:
3 TIniFile);
4 var
5 X: Integer;
6 begin
7 with StrGrid do
8 begin
9 RowCount := GridINI.ReadInteger(Section, 'RowCount', 0) + 1;
10 ColCount := GridINI.ReadInteger(Section, 'ColCount', 0);
11 for X := 1 to RowCount - 1 do
12 Cells[0, X] := GridINI.ReadString(Section, 'TitleY' + IntToStr(X), '');
13 for X := 1 to ColCount do
14 begin
15 Cells[X - 1, 0] := GridINI.ReadString(Section, 'TitleX' + IntToStr(X), '');
16 ColWidths[X - 1] := GridINI.ReadInteger(Section, 'ColW' + IntToStr(X),
17 DefaultColWidth)
18 end
19 end
20 end;
pretty simple, has 3 parameters, the first one of course the StringGrid to be
initialized the section wich would be the section in your INIFile where the
parameters are, and the INI file itself to extract the parameters from as you may
figure out your INIfile would look like this:
file: myprogram.ini
...
[grid]
RowCount=20
ColCount=4
TitleX1=FileName
TitleX2=Error description
TitleX3=Line
TitleX4=Tracking Number
ColW1=90
ColW2=250
ColW3=50
ColW4=200
...
//...pretty self explanative... I hope
InitGridFromINI(StringGrid, 'grid', MyIniFile);
that's it
|