Recent

Author Topic: Possible to copy one string list to another with single command?  (Read 356 times)

AMJF

  • New Member
  • *
  • Posts: 48
My project uses around a dozen string lists that are used for temporary storage of different types of string data, and when I need to transfer from one to another, I have to write a routine to manually clear the target string list and then use a loop to copy the lines over from the source, one by one.

Couldn't I use a simple command like this instead?

Code: Pascal  [Select][+][-]
  1. STRLST[2]:=STRLST[1];

I was also wondering about the settings for the string lists, like "Duplicates" and "Sorted" - would they be copied over, too? Most of my string lists are the same settings.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Possible to copy one string list to another with single command?
« Reply #1 on: March 29, 2023, 09:43:35 am »
Couldn't I use a simple command like this instead?
No, as object to object assignment has a different semantic (it only makes the two variables refer to the same object).
I was also wondering about the settings for the string lists, like "Duplicates" and "Sorted" - would they be copied over, too? Most of my string lists are the same settings.
Can't find any that does total deep copy, only data (both strings and associated objects, but shallow for objects) copy through TStrings.Assign.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Possible to copy one string list to another with single command?
« Reply #2 on: March 29, 2023, 09:52:38 am »
If you just want to copy them:

Code: Pascal  [Select][+][-]
  1. STRLST[2].Text := STRLST[1].Text;

(If STRLST is a list or array of TStringList, otherwise you're copying strings.)

Bart

  • Hero Member
  • *****
  • Posts: 5288
    • Bart en Mariska's Webstek
Re: Possible to copy one string list to another with single command?
« Reply #3 on: March 29, 2023, 10:47:54 am »
Assuming that STRLST is an aaray of TStringList:
Code: Pascal  [Select][+][-]
  1.   STRLST[2].Assign(STRLST[1]);

Bart

 

TinyPortal © 2005-2018