<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.soldat.pl/index.php?action=history&amp;feed=atom&amp;title=TStringList.Move</id>
		<title>TStringList.Move - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.soldat.pl/index.php?action=history&amp;feed=atom&amp;title=TStringList.Move"/>
		<link rel="alternate" type="text/html" href="https://wiki.soldat.pl/index.php?title=TStringList.Move&amp;action=history"/>
		<updated>2026-05-03T10:04:29Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https://wiki.soldat.pl/index.php?title=TStringList.Move&amp;diff=1157&amp;oldid=prev</id>
		<title>Mighty: new page</title>
		<link rel="alternate" type="text/html" href="https://wiki.soldat.pl/index.php?title=TStringList.Move&amp;diff=1157&amp;oldid=prev"/>
				<updated>2013-08-24T11:16:42Z</updated>
		
		<summary type="html">&lt;p&gt;new page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt; '''procedure Move(CurIndex, NewIndex: Integer)'''&lt;br /&gt;
  CurIndex: String index that is supposed to be moved&lt;br /&gt;
  NewIndex: Target index&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
[[TStringList.Move|Move]] moves the string at position ''CurIndex'' so it has position ''NewIndex'' after the move operation. The object associated to the string is also moved. &amp;lt;br&amp;gt;&lt;br /&gt;
''CurIndex'' and ''NewIndex'' should be in the range of 0 to Count-1, otherwise an exception occurs.&lt;br /&gt;
&lt;br /&gt;
==Warning==&lt;br /&gt;
''NewIndex'' is '''not''' the position in the stringlist before the move operation starts. The move operation&amp;lt;br&amp;gt;&lt;br /&gt;
1. removes the string from position CurIndex&amp;lt;br&amp;gt;&lt;br /&gt;
2. inserts the string at position NewIndex&amp;lt;br&amp;gt;&lt;br /&gt;
This may not lead to the desired result if ''NewIndex'' is bigger than ''CurIndex''. &amp;lt;br&amp;gt;&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pascal&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
With MyStrings do&lt;br /&gt;
begin&lt;br /&gt;
  Clear;&lt;br /&gt;
  Add('0');&lt;br /&gt;
  Add('1');&lt;br /&gt;
  Add('2');&lt;br /&gt;
  Add('3');&lt;br /&gt;
  Add('4');&lt;br /&gt;
  WriteLn(CommaText);&lt;br /&gt;
  // 0,1,2,3,4&lt;br /&gt;
  Move(1,3);&lt;br /&gt;
  WriteLn(CommaText);&lt;br /&gt;
  // 0,2,3,1,4&lt;br /&gt;
end;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Example swaps 2 random elements of the list. It takes care of the case described in ''Warning'' section. &amp;lt;br&amp;gt;{{note|this will be done when the server starts, and apparently [[ScriptCore3.Random|Random]] is dependant on soldatserver run time, and thus it will always generate the same pair of numbers in this particular example}}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pascal&amp;quot;&amp;gt;&lt;br /&gt;
var&lt;br /&gt;
  s: TStringList;&lt;br /&gt;
  i1,i2: integer;&lt;br /&gt;
&lt;br /&gt;
begin&lt;br /&gt;
  s := File.CreateStringList();&lt;br /&gt;
  s.Append('a');&lt;br /&gt;
  s.Append('b');&lt;br /&gt;
  s.Append('c');&lt;br /&gt;
  s.Append('d');&lt;br /&gt;
  s.Append('e');&lt;br /&gt;
  &lt;br /&gt;
  if s.Count &amp;gt; 1 then // check whether there are at least 2 strings&lt;br /&gt;
  begin&lt;br /&gt;
    // Generate 2 different indexes&lt;br /&gt;
    i1 := Random(0,s.Count-1);&lt;br /&gt;
    repeat&lt;br /&gt;
      i2 := Random(0,s.Count-1);&lt;br /&gt;
    until i1 &amp;lt;&amp;gt; i2;&lt;br /&gt;
    // handle the situation described in Warning section&lt;br /&gt;
    if i2 &amp;gt; i1+1 then &lt;br /&gt;
      Dec(i2);&lt;br /&gt;
    // all set&lt;br /&gt;
	&lt;br /&gt;
    s.Move(i1,i2);&lt;br /&gt;
    // WriteLn('Swapped strings number '+inttostr(i1)+' and '+inttostr(i2)+': '+s.CommaText);&lt;br /&gt;
    // uncomment line above to see the effect&lt;br /&gt;
  end&lt;br /&gt;
  else&lt;br /&gt;
    WriteLn('You need at least 2 strings in the list');&lt;br /&gt;
  &lt;br /&gt;
  s.Free;&lt;br /&gt;
end.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:TStringList]]&lt;/div&gt;</summary>
		<author><name>Mighty</name></author>	</entry>

	</feed>