Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's what I can see just by looking at the code:</p> <p>If think you have the parameters to <code>Explode</code> in the wrong order. The separator is the second parameter in the function to which you linked. So you should write:</p> <pre><code>Arry1 := Explode(RangeFrom, '.'); Arry2 := Explode(RangeTo, '.'); </code></pre> <hr> <p>You are leaking memory by not freeing the arrays returned by the <code>Explode</code> function. Delphi is different from PHP in that you often have to manage the memory of objects that you create.</p> <hr> <pre><code>a2 := Arry1[0]; b2 := Arry1[1]; c2 := Arry1[2]; d2 := Arry1[3]; </code></pre> <p>These should be <code>Arry2</code> rather than <code>Arry1</code>.</p> <hr> <p>You should convert the strings to integers up front. So declare them like this:</p> <pre><code>a1, b1, c1, d1, a2, b2, c2, d2: Integer; </code></pre> <p>and write the assignments like this:</p> <pre><code>a1 := StrToInt(Arry1[0]); b1 := StrToInt(Arry1[1]); //etc. etc. </code></pre> <hr> <pre><code>while ($d2 &gt;= $d1 || $c2 &gt; $c1 || $b2 &gt; $b1 || $a2 &gt; $a1) </code></pre> <p>translates to:</p> <pre><code>while ((d2 &gt;= d1) or (c2 &gt; c1) or (b2 &gt; b1) or (a2 &gt; a1)) </code></pre> <hr> <p>Inside the while loop you want code like this:</p> <pre><code>if d1 &gt; 255 then begin d1 := 1; inc(c1); end; </code></pre> <hr> <p>Converting the 4 values back to an IP address is easiest with the <code>Format</code> function:</p> <pre><code>ListBox1.Items.Add(Format('%d.%d.%d.%d', [a1, b1, c1, d1])); </code></pre> <hr> <p>You have a mis-understanding of what <code>StrToInt</code> does it is a function that receives as input a string and returns an integer. When you write:</p> <pre><code>StrToInt(d1)+1 </code></pre> <p>you are not modifying the variable <code>d1</code> which is just an input variable. That issue disappears when you make the other changes I describe, but I wanted to point it out for your future benefit.</p> <hr> <p>You may also want to force a periodic repaint of the list box so that you can see what is happening.</p> <hr> <p>Put it all together and you have this:</p> <pre><code>var Arry1, Arry2: TStringList; RangeFrom, RangeTo: string; Count: Integer; a1, b1, c1, d1, a2, b2, c2, d2: Integer; begin RangeFrom := Edit1.Text; RangeTo := Edit2.Text; Arry1 := Explode(RangeFrom, '.'); try a1 := StrToInt(Arry1[0]); b1 := StrToInt(Arry1[1]); c1 := StrToInt(Arry1[2]); d1 := StrToInt(Arry1[3]); finally Arry1.Free; end; Arry2 := Explode(RangeTo, '.'); try a2 := StrToInt(Arry2[0]); b2 := StrToInt(Arry2[1]); c2 := StrToInt(Arry2[2]); d2 := StrToInt(Arry2[3]); finally Arry2.Free; end; Count := 0; while ((d2 &gt;= d1) or (c2 &gt; c1) or (b2 &gt; b1) or (a2 &gt; a1)) do begin if d1 &gt; 255 then begin d1 := 1; inc(c1); end; if c1 &gt; 255 then begin c1 := 1; inc(b1); end; if b1 &gt; 255 then begin b1 := 1; inc(a1); end; ListBox1.Items.Add(Format('%d.%d.%d.%d', [a1, b1, c1, d1])); inc(Count); if Count mod 1000=0 then begin ListBox1.Repaint; ListBox1.TopIndex := ListBox1.Items.Count-1; end; inc(d1); end; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload