Solved

merging strings within a tstringlist

Posted on 2004-08-26
4
503 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
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 …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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