Solved

merging strings within a tstringlist

Posted on 2004-08-26
4
450 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
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
bpana earned 125 total points
Comment Utility
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
Comment Utility
use it as
CombineStrList(tsComingSoon);
0
 
LVL 8

Assisted Solution

by:Cesario
Cesario earned 50 total points
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now