Forum > General

Possible to copy one string list to another with single command?

(1/1)

AMJF:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:

--- Quote from: AMJF on March 29, 2023, 09:15:52 am ---Couldn't I use a simple command like this instead?

--- End quote ---
No, as object to object assignment has a different semantic (it only makes the two variables refer to the same object).

--- Quote from: AMJF on March 29, 2023, 09:15:52 am ---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.

--- End quote ---
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:
If you just want to copy them:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---STRLST[2].Text := STRLST[1].Text;
(If STRLST is a list or array of TStringList, otherwise you're copying strings.)

Bart:
Assuming that STRLST is an aaray of TStringList:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  STRLST[2].Assign(STRLST[1]);
Bart

Navigation

[0] Message Index

Go to full version