Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Initialize StringGrid from INI file Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
09-Nov-03
Category
VCL-General
Language
Delphi 2.x
Views
100
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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 

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC