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