Solved

merging strings within a tstringlist

Posted on 2004-08-26
4
511 Views
Last Modified: 2010-04-05
hey all,
{ This function will take a tstringlist and combine all }
{ strings within that stringlist into a single string   }
{ within the same tstringlist. In other words, all      }
{ tsLST.strings[x] will be merged into tsLST.strings[0] }

Function CombineStrList(tsLST: TStringList): TStringList;
var
  i : integer;
  tsTMP: TStringList;
begin
  tsTMP := TStringList.Create;
  try
    tsTMP.Add('');
    for i:= 0 to tsLST.count -1  do  begin
      tsTMP[0] := tsTMP[0] + tsLST.strings[i];
    end;
    CombineStrList := tsTMP;
  finally
    tsTMP.Free;
  end;
end;

-------------
I know Im missing something easy, but when I tried to run this function I get an access violation error.
The following will make the err:
-------------
var
  tsComingSoon  : TStringList;

tsComingSoon := CombineStrList(tsComingSoon);
-------------

tsComingSoon has a few strings within the stringlist, and when I send it to the function it is combined correctly into tsTMP stringlist.
but when I try to access the new tsComingSoon stringlist I get the error.

any help would be nice :)

0
Comment
Question by:LMuadDIb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
bpana earned 125 total points
ID: 11908164
procedure CombineStrList(var tsLST: TStringList);
var
  s: string;
  i: integer;
begin
  s := '';
  for i := 0 to tsLST.Count - 1 do
  begin
    s := s + tsLST.Strings[i];
  end;
  tsLST.Clear;
  tsLST.Add(s);
end;
0
 
LVL 6

Expert Comment

by:bpana
ID: 11908174
use it as
CombineStrList(tsComingSoon);
0
 
LVL 8

Assisted Solution

by:Cesario
Cesario earned 50 total points
ID: 11908379
Hi,

Function CombineStrList(tsLST: TStringList): TStringList;
VAR
 NewList : TStringList;
begin
   NewList := TStringList.Create;
   NewList.Add ( StringReplace(tsLst.text,#13#10,'',[rfReplaceAll]));
   Result := NewList;
End;


best Regards

Cesario
0
 
LVL 4

Author Comment

by:LMuadDIb
ID: 11909736
gave the pts to bpana for the quick reply
but I added a few more pts and gave some to Cesario for his idea.
I would use Cesario idea, but I wanted to keep the integrity of the strings intact... didnt want to loose the formating sense the strings are made up of html code & text
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question