Solved

merging strings within a tstringlist

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

815 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

12 Experts available now in Live!

Get 1:1 Help Now