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 save two TStringlists to the same stream 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
18-Oct-02
Category
Object Pascal-Strings
Language
Delphi 2.x
Views
29
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

TStrings.LoadFromStream is assuming that itself consumes the rest of the stream! 
What if I want to save 2 stringlists to the same stream?

Answer:

That is as designed. Just use an intermediate stream to accomplish what you want. 
Or you can take the following approach using a string buffer:

1   { ... }
2   var
3     list1: TStringList;
4     list2: TStringList;
5     lng: cardinal;
6     stream: TMemoryStream;
7     tmpS: string;
8   begin
9     list1 := TStringList.Create;
10    list2 := TStringList.Create;
11    try
12      stream := TMemoryStream.Create;
13      try
14        {Assume there was code to get something into stream. 
15  			The layout of the stream is:
16        size1|block1|size2|block2}
17        {Read size of the 1st block}
18        stream.read(lng, SizeOf(lng));
19        if lng > 0 then
20        begin
21          {if there are contents, read the block to tmpS}
22          SetLength(tmpS, lng);
23          stream.read(tmpS[1], lng)
24            {Assign tmpS to the Text property of list1}
25          list1.Text := tmpS;
26        end;
27        {Same procedure for list2}
28        stream.read(lng, SizeOf(lng));
29        if lng > 0 then
30        begin
31          SetLength(tmpS, lng);
32          stream.read(tmpS[1], lng)
33            list2.Text := tmpS;
34        end;
35      finally
36      end;
37    finally
38      list2.Free;
39      list1.Free;
40    end;
41  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