AddStrings
Code: Pascal [Select][+][-]{$ifdef fpc}{$mode delphi}{$H+}{$endif}uses classes;const ca:array[0..2] of string = ('a','b','c'); cb:array[0..2] of string = ('d','e','f'); var a,b:Tstrings;begin a:=Tstringlist.create; b:=Tstringlist.create; a.Addstrings(ca); b.AddStrings(cb); a.addstrings(b); writeln(a.text); b.free; a.free; end.
Code: Pascal [Select][+][-]New := JoinSLs(Old,New); // wrong values
Quote from: torbente on July 19, 2018, 10:03:52 pmCode: Pascal [Select][+][-]New := JoinSLs(Old,New); // wrong valuesPlease refrain from this type of usage, because:You are not freeing New before assignment. That is a memory leak.You are assigning Old to New through the code of this function. Later when you free one of them you are also, unintentionally, freeing the other.
Please refrain from this type of usage, because:
Code: Pascal [Select][+][-]OldStringList.AddStrings(NewStringlist);NewStringList.Clear;NewStringList.AddStrings(OldStringList)AFAIK it can not be optimizied beyond this point... or im wrong again?(optimization for this is pretty important since this is a VERY common situation in my app)