Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7022779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:37:34+00:00 2026-05-27T23:37:34+00:00

Hello everybody, I have a small code in PHP that I would like to

  • 0

Hello everybody,

I have a small code in PHP that I would like to convert in Delphi and I have some troubles…
Here is the PHP code :

$from = "121.198.0.0";
$to = "121.198.255.255";
$arry1 = explode(".", $from);
$arry2 = explode(".", $to);
$a1    = $arry1[0];
$b1    = $arry1[1];
$c1    = $arry1[2];
$d1    = $arry1[3];
$a2    = $arry2[0];
$b2    = $arry2[1];
$c2    = $arry2[2];
$d2    = $arry2[3];
while ($d2 >= $d1 || $c2 > $c1 || $b2 > $b1 || $a2 > $a1) {
    if ($d1 > 255) {
        $d1 = 1;
        $c1++;
    }
    if ($c1 > 255) {
        $c1 = 1;
        $b1++;
    }
    if ($b1 > 255) {
        $b1 = 1;
        $a1++;
    }
    echo "$a1.$b1.$c1.$d1<br>";
    $d1++;
}

And in Delphi I started with that :

procedure TForm1.Button1Click(Sender: TObject);
var
  Arry1, Arry2: TStringList;
  RangeFrom, RangeTo: string;
  a1, b1, c1, d1, a2, b2, c2, d2: string;
begin
  RangeFrom := Edit1.Text;
  RangeTo := Edit2.Text;
  Arry1 := Explode('.', RangeFrom);
  Arry2 := Explode('.', RangeTo);
  a1 := Arry1[0];
  b1 := Arry1[1];
  c1 := Arry1[2];
  d1 := Arry1[3];
  a2 := Arry1[0];
  b2 := Arry1[1];
  c2 := Arry1[2];
  d2 := Arry1[3];
  while (StrToInt(d2) >= StrToInt(d1))
    //and StrToInt(c2) > (StrToInt(c1)
    //and StrToInt(b2) > (StrToInt(b1)
    //and StrToInt(a2) > (StrToInt(a1)
  do
  begin
    if (StrToInt(d1) > 255) then
    begin
        d1 := '1';
        StrToInt(c1)+1;
    end;
    if (StrToInt(c1) > 255) then
    begin
        c1 := '1';
        StrToInt(b1)+1;
    end;
    if (StrToInt(b1) > 255) then
    begin
        b1 := '1';
        StrToInt(a1)+1;
    end;
    ListBox1.Items.Add(a1+'.'+b1+'.'+c1+'.'+d1);
    StrToInt(d1)+1;
  end;
end;

(For the Explode function, I use : http://www.marcosdellantonio.net/2007/06/14/funcao-explode-do-php-em-delphi/)

Someone can help me to make working this small code in Delphi ?

Thanks in advance 🙂

Beny

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:37:34+00:00Added an answer on May 27, 2026 at 11:37 pm

    Here’s what I can see just by looking at the code:

    If think you have the parameters to Explode in the wrong order. The separator is the second parameter in the function to which you linked. So you should write:

    Arry1 := Explode(RangeFrom, '.');
    Arry2 := Explode(RangeTo, '.');
    

    You are leaking memory by not freeing the arrays returned by the Explode function. Delphi is different from PHP in that you often have to manage the memory of objects that you create.


    a2 := Arry1[0];
    b2 := Arry1[1];
    c2 := Arry1[2];
    d2 := Arry1[3];
    

    These should be Arry2 rather than Arry1.


    You should convert the strings to integers up front. So declare them like this:

    a1, b1, c1, d1, a2, b2, c2, d2: Integer;
    

    and write the assignments like this:

    a1 := StrToInt(Arry1[0]);
    b1 := StrToInt(Arry1[1]);
    //etc. etc.
    

    while ($d2 >= $d1 || $c2 > $c1 || $b2 > $b1 || $a2 > $a1)
    

    translates to:

    while ((d2 >= d1) or (c2 > c1) or (b2 > b1) or (a2 > a1))
    

    Inside the while loop you want code like this:

    if d1 > 255 then
    begin
      d1 := 1;
      inc(c1);
    end;
    

    Converting the 4 values back to an IP address is easiest with the Format function:

    ListBox1.Items.Add(Format('%d.%d.%d.%d', [a1, b1, c1, d1]));
    

    You have a mis-understanding of what StrToInt does it is a function that receives as input a string and returns an integer. When you write:

    StrToInt(d1)+1
    

    you are not modifying the variable d1 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.


    You may also want to force a periodic repaint of the list box so that you can see what is happening.


    Put it all together and you have this:

    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 >= d1) or (c2 > c1) or (b2 > b1) or (a2 > a1)) do
      begin
        if d1 > 255 then
        begin
          d1 := 1;
          inc(c1);
        end;
        if c1 > 255 then
        begin
          c1 := 1;
          inc(b1);
        end;
        if b1 > 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;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have some code: <?php echo Hello Everybody!; echo <br/> ; $var1
Hello everybody! I have a SQL (see above) and i would like to know
Hello i would like do somthing like that: <?php $count = 0; foreach($a as
Hello everybody I have a LINQ declaration like this : var query = from
Suppose I have String str=Hello $everybody$. How $are$ you $all$; From above string, I
Hello everybody. I would like to know how to download and save a file
Note: This question is posted here hello everybody, I have a predefind list of
Hello everybody I have some certs in SQL 2008 but am by no means
Hello everybody and thanks for interest some time ago i have started to use
Hello everybody I have this string: [JOLLY BLU at STAY SHIP, Voy: 0275/11] How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.