Articles   Members Online: 3
-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
How to store a text file in a resource and display the lines in a TStringGrid at 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
30-Aug-02
Category
Files Operation
Language
Delphi 2.x
Views
107
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I am trying to work out how to store approximately 1000 lines of text (3 columns, 
30 chars each) inside an application. I want to read the values and then display 
them in a TStringGrid and do some further manipulation.

Answer:

If you want to read the data into a stringgrid a way to do that without building a 
class around the resource data would be this. You start by placing the data into a 
file and the file into a resource as detailed in Tip Number 1004. Loading this data 
into a TStringGrid would work like this:


1   procedure LoadResourceIntoGrid(grid: TStringGrid);
2   var
3     rs: TResourceStream;
4     numElements: Integer;
5     datarec: TFileData;
6     i: Integer;
7   begin
8     rs := TResourceStream.Create(hInstance, 'FILEDATA', RT_RCDATA);
9     try
10      numElements := rs.Size div Sizeof(numElements);
11      grid.Perform(WM_SETREDRAW, 0, 0);
12      try
13        grid.RowCount := numElements + 1; {assuming a header row}
14        {following assumes grids colcount has been set correctly already}
15        for i := 1 to numElements do
16        begin
17          rs.ReadBuffer(datarec, sizeof(datarec));
18          grid.Cells[grid.FixedCols, i] := datarec.col1;
19          grid.Cells[grid.FixedCols + 1, i] := datarec.col2;
20          grid.Cells[grid.FixedCols + 2, i] := datarec.col3;
21        end;
22      finally
23        grid.Perform(WM_SETREDRAW, 1, 0);
24        grid.Invalidate;
25      end;
26    finally
27      rs.free
28    end;
29  end;


			
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