How to fix get IP-MAC pairs code below from Delphi 7 to Delphi 2009 ?

How to get All  IP - MAC address pairs on local PC  by Delphi 2009 ?

The Code below can get correct answer on Delphi 7,
but  get error answer on Delphi 2009. 
How to fix ?  or Are there the better method ?


// Delphi 7 (Delphi 2009 failed)
//
// Get  Alll  IP-MAC address pairs on local PC
//
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

   function GetIPMAC: String;

const
  ANY_SIZE      = 1;
  MAX_ADAPTER_ADDRESS_LENGTH = 8; // arb.

  MAX_INTERFACE_NAME_LEN = 256; { mrapi.h }
  MAXLEN_PHYSADDR = 8; { iprtrmib.h }
  MAXLEN_IFDESCR = 256; { --"---     }

type

//----------- MibIf STRUCTURES------------------------------------------------------

  PTMibIfRow = ^TMibIfRow;
  TMibIfRow = packed record
    wszName: array[1..MAX_INTERFACE_NAME_LEN] of WCHAR;
    dwIndex: DWORD;
    dwType: DWORD;
    dwMTU: DWORD;
    dwSpeed: DWORD;
    dwPhysAddrLen: DWORD;
    bPhysAddr: array[1..MAXLEN_PHYSADDR] of byte;
    dwAdminStatus: DWORD;
    dwOperStatus: DWORD;
    dwLastChange: DWORD;
    dwInOctets: DWORD;
    dwInUcastPkts: DWORD;
    dwInNUCastPkts: DWORD;
    dwInDiscards: DWORD;
    dwInErrors: DWORD;
    dwInUnknownProtos: DWORD;
    dwOutOctets: DWORD;
    dwOutUCastPkts: DWORD;
    dwOutNUCastPkts: DWORD;
    dwOutDiscards: DWORD;
    dwOutErrors: DWORD;
    dwOutQLen: DWORD;
    dwDescrLen: DWORD;
    bDescr: array[1..MAXLEN_IFDESCR] of char; //byte;
  end;

  TMIBIfArray = array of TMIBIFRow;

  PTMibIfTable = ^TMIBIfTable;

  TMibIfTable = packed record
    dwNumEntries: DWORD;
    Table: array[0..ANY_SIZE - 1] of TMibIfRow;
  end;

//----------- MibIPAddr STRUCTURES------------------------------------------------------

  TMacAddress = array[1..MAX_ADAPTER_ADDRESS_LENGTH] of byte;

  PTMibIPAddrRow = ^TMibIPAddrRow;
  TMibIPAddrRow = packed record
    dwAddr: DWORD;
    dwIndex: DWORD;
    dwMask: DWORD;
    dwBCastAddr: DWORD;
    dwReasmSize: DWORD;
    Unused1,
      Unused2: WORD;
  end;

  TMibIPAddrArray = array of TMIBIPAddrRow;

  PTMibIPAddrTable = ^TMibIPAddrTable;
  TMibIPAddrTable = packed record
    dwNumEntries: DWORD;
    Table: array[0..ANY_SIZE - 1] of TMibIPAddrRow;
  end;

  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);

    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

  function GetIfTable( pIfTable: PTMibIfTable; pdwSize: PULONG; bOrder: boolean ): DWORD;  stdCall; external 'IPHLPAPI.DLL';
  function GetIpAddrTable( pIpAddrTable: PTMibIPAddrTable;  pdwSize: PULONG;  bOrder: BOOL ): DWORD; stdcall; external 'IPHLPAPI.DLL';


procedure Get_IfTableMIB( var MIBIfArray: TMIBIfArray ; var NumEntries: DWORD );
var
  i,
    Error,
    TableSize   : integer;
  pBuf          : PChar;
//  NumEntries    : DWORD;
  sDescr,
    Temp        : string;
begin
  TableSize := 0;
   // first call: get memsize needed
  Error := GetIfTable( PTMibIfTable( pBuf ), @TableSize, false );
  if Error <> ERROR_INSUFFICIENT_BUFFER then
    EXIT;
  GetMem( pBuf, TableSize );

   // get table pointer
  Error := GetIfTable( PTMibIfTable( pBuf ), @TableSize, false );
  if Error = NO_ERROR then
  begin
    NumEntries := PTMibIfTable( pBuf )^.dwNumEntries;
    if NumEntries > 0 then
    begin
      SetLength( MIBIfArray, NumEntries );
      inc( pBuf, SizeOf( NumEntries ) );
      for i := 0 to pred(NumEntries) do
      begin
        MIBIfArray[i] := PTMibIfRow( pBuf )^;
        inc( pBuf, SizeOf( TMIBIfRow ) );
      end;
    end
  end;
  dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( TMIBIfRow ) );
  FreeMem( pBuf );
end;

procedure Get_IPAddrTableMIB( var IPAddrTable:TMibIPAddrArray  );
var
  IPAddrRow     : TMibIPAddrRow;
  TableSize     : DWORD;
  ErrorCode     : DWORD;
  i             : integer;
  pBuf          : PChar;
  NumEntries    : DWORD;
begin
  TableSize := 0; ;
  // first call: get table length
  ErrorCode := GetIpAddrTable( PTMibIPAddrTable( pBuf ), @TableSize, true );
  if Errorcode <> ERROR_INSUFFICIENT_BUFFER then
    EXIT;

  GetMem( pBuf, TableSize );
  // get table
  ErrorCode := GetIpAddrTable( PTMibIPAddrTable( pBuf ), @TableSize, true );
  if ErrorCode = NO_ERROR then
  begin
    NumEntries := PTMibIPAddrTable( pBuf )^.dwNumEntries;
    if NumEntries > 0 then
    begin
      SetLength( IPAddrTable, NumEntries);
      inc( pBuf, SizeOf( DWORD ) );
      for i := 1 to NumEntries do
      begin
        IPAddrTable[ i-1 ] := PTMIBIPAddrRow( pBuf )^;
        inc( pBuf, SizeOf( TMIBIPAddrRow ) );
      end;
    end;
  end;

  // we must restore pointer!
  dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( IPAddrRow ) );
  FreeMem( pBuf );
end;

function IpAddr2Str( IPAddr: DWORD ): string;
var
  i             : integer;
begin
  Result := '';
  for i := 1 to 4 do
  begin
    Result := Result + Format( '%3d.', [IPAddr and $FF] );
    IPAddr := IPAddr shr 8;
  end;
  Delete( Result, Length( Result ), 1 );
end; {*IpAddr2Str*}

function GetIPFromIFIndex(InterfaceIndex: Cardinal): string;
var
 i:  integer;
 IPArr : TMIBIPAddrArray;
begin
   Result := '!not_found!';  // shouldn't happen...
   Get_IPAddrTableMIB( IpArr );  // get IP-address table
   if Length(IPArr) > 0 then
     for i := low(IPArr) to High(IPArr) do  // look for matching index...
       if IPArr[i].dwIndex = InterfaceIndex then
       begin
         Result := IPAddr2Str(IParr[i].dwAddr);
         BREAK;
       end;
end; (*GetIPFromIFIndex*)


function MacAddr2Str( MacAddr: TMacAddress; size: integer ): string;
{ converts numerical MAC-address to ww-xx-yy-zz string }
var
  i             : integer;
begin
  if Size = 0 then
  begin
    Result := '00-00-00-00-00-00';
    EXIT;
  end
  else Result := '';
  //
  for i := 1 to Size do
    Result := Result + IntToHex( MacAddr[i], 2 ) + '-';
  Delete( Result, Length( Result ), 1 );
end; {*MacAddr2Str*}

function GetIPMAC: String;
var
  MibArr : TMIBIfArray;
  IP : String;
  Mac : String;
  i,Num : Integer;
  NumEntries : DWORD;

begin

  Get_IfTableMIB(MibArr,  NumEntries);  // get current MIB data
  Num:=StrToInt(IntToStr(NumEntries))-1;
  Result :='';
  for i:=0 to Num do
  begin
    IP := GetIPFromIFIndex(MibArr[i].dwIndex);
    Mac := MacAddr2Str(TMacAddress(MibArr[i].bPhysAddr), MibArr[i].dwPhysAddrLen);

//    Memo1.Lines.Add('bDescr : ' + MibArr[i].bDescr);
    Result := Result + IP + ' (' + MAC + ') ' + #13#10;
  end;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Lines.Add(GetIPMAC);
end;

end.
0
ICST
5/6/2009 1:18:03 AM
embarcadero.delphi.vcl.using 2297 articles. 1 followers. Follow

6 Replies
1526 Views

Similar Articles

[PageSpeed] 29

> The Code below can get correct answer on Delphi 7,
> but  get error answer on Delphi 2009. 
> How to fix ?  

What's the big change in D2009?  Unicode: string being mapped to
UnicodeString, Char to WideChar and PChar to PWideChar.  So, let's look
for declarations of variables or parameters with one of those types -

>    function GetIPMAC: String;

Hmm, here's one.  No implementation yet, so let's carry on...

>     bDescr: array[1..MAXLEN_IFDESCR] of char; //byte;

Even without double-checking MSDN, that looks suspcious - 'bDescr' (and
the comment!) implies the elements are byte-sized, so replace char with
AnsiChar (this *should* have been the case when code was originally
written of course).

>   function GetIfTable( pIfTable: PTMibIfTable; pdwSize: PULONG;
> bOrder: boolean ): DWORD;  stdCall; external 'IPHLPAPI.DLL';
> function GetIpAddrTable( pIpAddrTable: PTMibIPAddrTable;  pdwSize:
> PULONG;  bOrder: BOOL ): DWORD; stdcall; external 'IPHLPAPI.DLL';

Not do to with strings, but are the bOrder arguments BOOL (= 4 bytes)
or Boolean (= 1 byte)?  You should check this - doing one of each was a
bug even in D7!

>   pBuf          : PChar;

Ah, a PChar.  We may be on to something!

>   sDescr,
>     Temp        : string;

And a couple of strings...

>       inc( pBuf, SizeOf( NumEntries ) );

Ker-ching!  If you check out the help, you'll see that Inc increments a
pointer variable by the size of the pointed to type.  Thus, when PChar
= PWideChar (as it is in D2009), the line quoted increments the pointer
by SizeOf( NumEntries ) * 2.  Change pBuf to be of type PAnsiChar
(again, strictly speaking, it should have been so all along), and you
should have made the crucial fix.

>   dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( TMIBIfRow ) );

Again, Dec is like Inc - change the type of pBuf, and all should be
well.  (By the by, what were those strings decalred for?  They haven't
been used!)

>   FreeMem( pBuf );
> end;
> 
> procedure Get_IPAddrTableMIB( var IPAddrTable:TMibIPAddrArray  );
> var
>   IPAddrRow     : TMibIPAddrRow;
>   TableSize     : DWORD;
>   ErrorCode     : DWORD;
>   i             : integer;
>   pBuf          : PChar;

Grr, another one!  Again, change it to PAnsiChar.

<snip>

> function IpAddr2Str( IPAddr: DWORD ): string;
> var
>   i             : integer;
> begin
>   Result := '';
>   for i := 1 to 4 do
>   begin
>     Result := Result + Format( '%3d.', [IPAddr and $FF] );
>     IPAddr := IPAddr shr 8;
>   end;
>   Delete( Result, Length( Result ), 1 );
> end; {*IpAddr2Str*}

Should be fine, even if a bit inefficient (an inefficiency that is
nothing to do with D2009 - I would pre-allocate the string myself,
though I doubt this would make any practical difference speed-wise).

> function GetIPFromIFIndex(InterfaceIndex: Cardinal): string;

Again, not an error as such, but why not declare the parameter as a
DWORD, given a DWORD value is what you're comparing it to?  For sure, a
Cardinal in 32 bit Delphi *is* a DWORD, but even still...

<snip>

>   Num:=StrToInt(IntToStr(NumEntries))-1;

Er... you have a number, which you convert to a string only to
immediately convert it back to an integer!

<snip rest, looks OK but for a repeat of the minor inefficiency issue
mentioned above>
0
Chris
5/6/2009 1:50:00 AM
Thank you very much. ^_^
I success ! Code is as below.

// Delphi 7 , Delphi 2009
//
// ε–εΎ—ζ‰€ζœ‰ IP-MAC
//
// Ref:  https://forums.codegear.com/thread.jspa?threadID=16953&tstart=0
//
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

   function GetIPMAC: String;

const
  ANY_SIZE      = 1;
  MAX_ADAPTER_ADDRESS_LENGTH = 8; // arb.

  MAX_INTERFACE_NAME_LEN = 256; { mrapi.h }
  MAXLEN_PHYSADDR = 8; { iprtrmib.h }
  MAXLEN_IFDESCR = 256; { --"---     }

type

//----------- MibIf STRUCTURES------------------------------------------------------

  PTMibIfRow = ^TMibIfRow;
  TMibIfRow = packed record
    wszName: array[1..MAX_INTERFACE_NAME_LEN] of WCHAR;
    dwIndex: DWORD;
    dwType: DWORD;
    dwMTU: DWORD;
    dwSpeed: DWORD;
    dwPhysAddrLen: DWORD;
    bPhysAddr: array[1..MAXLEN_PHYSADDR] of byte;
    dwAdminStatus: DWORD;
    dwOperStatus: DWORD;
    dwLastChange: DWORD;
    dwInOctets: DWORD;
    dwInUcastPkts: DWORD;
    dwInNUCastPkts: DWORD;
    dwInDiscards: DWORD;
    dwInErrors: DWORD;
    dwInUnknownProtos: DWORD;
    dwOutOctets: DWORD;
    dwOutUCastPkts: DWORD;
    dwOutNUCastPkts: DWORD;
    dwOutDiscards: DWORD;
    dwOutErrors: DWORD;
    dwOutQLen: DWORD;
    dwDescrLen: DWORD;
//    bDescr: array[1..MAXLEN_IFDESCR] of char; //byte;
    bDescr: array[1..MAXLEN_IFDESCR] of AnsiChar; //byte;
  end;

  TMIBIfArray = array of TMIBIFRow;

  PTMibIfTable = ^TMIBIfTable;

  TMibIfTable = packed record
    dwNumEntries: DWORD;
    Table: array[0..ANY_SIZE - 1] of TMibIfRow;
  end;

//----------- MibIPAddr STRUCTURES------------------------------------------------------

  TMacAddress = array[1..MAX_ADAPTER_ADDRESS_LENGTH] of byte;

  PTMibIPAddrRow = ^TMibIPAddrRow;
  TMibIPAddrRow = packed record
    dwAddr: DWORD;
    dwIndex: DWORD;
    dwMask: DWORD;
    dwBCastAddr: DWORD;
    dwReasmSize: DWORD;
    Unused1,
      Unused2: WORD;
  end;

  TMibIPAddrArray = array of TMIBIPAddrRow;

  PTMibIPAddrTable = ^TMibIPAddrTable;
  TMibIPAddrTable = packed record
    dwNumEntries: DWORD;
    Table: array[0..ANY_SIZE - 1] of TMibIPAddrRow;
  end;

  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);

    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

  function GetIfTable( pIfTable: PTMibIfTable; pdwSize: PULONG; bOrder: boolean ): DWORD;  stdCall; external 'IPHLPAPI.DLL';
  function GetIpAddrTable( pIpAddrTable: PTMibIPAddrTable;  pdwSize: PULONG;  bOrder: BOOL ): DWORD; stdcall; external 'IPHLPAPI.DLL';


procedure Get_IfTableMIB( var MIBIfArray: TMIBIfArray ; var NumEntries: DWORD );
var
  i,
    Error,
    TableSize   : integer;
//  pBuf          : PChar;
  pBuf          : PAnsiChar;
//  NumEntries    : DWORD;
//  sDescr, Temp        : string;
  sDescr, Temp        : Ansistring;
begin
  TableSize := 0;
   // first call: get memsize needed
  Error := GetIfTable( PTMibIfTable( pBuf ), @TableSize, false );
  if Error <> ERROR_INSUFFICIENT_BUFFER then
    EXIT;
  GetMem( pBuf, TableSize );

   // get table pointer
  Error := GetIfTable( PTMibIfTable( pBuf ), @TableSize, false );
  if Error = NO_ERROR then
  begin
    NumEntries := PTMibIfTable( pBuf )^.dwNumEntries;
    if NumEntries > 0 then
    begin
      SetLength( MIBIfArray, NumEntries );
      inc( pBuf, SizeOf( NumEntries ) );
      for i := 0 to pred(NumEntries) do
      begin
        MIBIfArray[i] := PTMibIfRow( pBuf )^;
        inc( pBuf, SizeOf( TMIBIfRow ) );
      end;
    end
  end;
  dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( TMIBIfRow ) );
  FreeMem( pBuf );
end;

procedure Get_IPAddrTableMIB( var IPAddrTable:TMibIPAddrArray  );
var
  IPAddrRow     : TMibIPAddrRow;
  TableSize     : DWORD;
  ErrorCode     : DWORD;
  i             : integer;
//  pBuf          : PChar;
  pBuf          : PAnsiChar;
  NumEntries    : DWORD;
begin
  TableSize := 0; ;
  // first call: get table length
  ErrorCode := GetIpAddrTable( PTMibIPAddrTable( pBuf ), @TableSize, true );
  if Errorcode <> ERROR_INSUFFICIENT_BUFFER then
    EXIT;

  GetMem( pBuf, TableSize );
  // get table
  ErrorCode := GetIpAddrTable( PTMibIPAddrTable( pBuf ), @TableSize, true );
  if ErrorCode = NO_ERROR then
  begin
    NumEntries := PTMibIPAddrTable( pBuf )^.dwNumEntries;
    if NumEntries > 0 then
    begin
      SetLength( IPAddrTable, NumEntries);
      inc( pBuf, SizeOf( DWORD ) );
      for i := 1 to NumEntries do
      begin
        IPAddrTable[ i-1 ] := PTMIBIPAddrRow( pBuf )^;
        inc( pBuf, SizeOf( TMIBIPAddrRow ) );
      end;
    end;
  end;

  // we must restore pointer!
  dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( IPAddrRow ) );
  FreeMem( pBuf );
end;

function IpAddr2Str( IPAddr: DWORD ): string;
var
  i             : integer;
begin
  Result := '';
  for i := 1 to 4 do
  begin
    Result := Result + Format( '%3d.', [IPAddr and $FF] );
    IPAddr := IPAddr shr 8;
  end;
  Delete( Result, Length( Result ), 1 );
end; {*IpAddr2Str*}

function GetIPFromIFIndex(InterfaceIndex: Cardinal): string;
var
 i:  integer;
 IPArr : TMIBIPAddrArray;
begin
   Result := '!not_found!';  // shouldn't happen...
   Get_IPAddrTableMIB( IpArr );  // get IP-address table
   if Length(IPArr) > 0 then
     for i := low(IPArr) to High(IPArr) do  // look for matching index...
       if IPArr[i].dwIndex = InterfaceIndex then
       begin
         Result := IPAddr2Str(IParr[i].dwAddr);
         BREAK;
       end;
end; (*GetIPFromIFIndex*)


function MacAddr2Str( MacAddr: TMacAddress; size: integer ): string;
{ converts numerical MAC-address to ww-xx-yy-zz string }
var
  i             : integer;
begin
  if Size = 0 then
  begin
    Result := '00-00-00-00-00-00';
    EXIT;
  end
  else Result := '';
  //
  for i := 1 to Size do
    Result := Result + IntToHex( MacAddr[i], 2 ) + '-';
  Delete( Result, Length( Result ), 1 );
end; {*MacAddr2Str*}

function GetIPMAC: String;
var
  MibArr : TMIBIfArray;
//  IP : String;
//  Mac : String;
  IP : AnsiString;
  Mac : AnsiString;
  i,Num : Integer;
  NumEntries : DWORD;

begin

  Get_IfTableMIB(MibArr,  NumEntries);  // get current MIB data
  Num:=StrToInt(IntToStr(NumEntries))-1;
  Result :='';
  for i:=0 to Num do
  begin
    IP := GetIPFromIFIndex(MibArr[i].dwIndex);
    Mac := MacAddr2Str(TMacAddress(MibArr[i].bPhysAddr), MibArr[i].dwPhysAddrLen);

//    Memo1.Lines.Add('bDescr : ' + MibArr[i].bDescr);
    Result := Result + IP + ' (' + MAC + ') ' + #13#10;
  end;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Lines.Add(GetIPMAC);
end;

end.
0
ICST
5/6/2009 12:28:45 PM
Do you know any simple method to get ALL  IP-MAC  pairs on local host ?
0
ICST
5/6/2009 12:29:55 PM
> Do you know any simple method to get ALL  IP-MAC  pairs on local host ?
I use this method:

Note it calls Coinitialize which is not necessary in a normal 
application but I need to call it in my server app.

You have to import the windows scripting host tlb in order to get this 
function to work.

uses WbemScripting_TLB;

function ExtractMACAddresses: TStringList;
function ExtractList : TStringList;
var locator : ISWbemLocator;
     services : ISWbemServices;
     networkConfigurations : ISWbemObjectSet;
     networkCards : IEnumVARIANT;
     obj : ISWbemObject;
     TempObj: OleVariant;                  // temporary used values
     tempVal: Cardinal;
     s : string;
     vals : Variant;
     i : integer;
begin
      Result := TStringList.Create;
      try
         locator := CoSWbemLocator.Create;
         if not Assigned(locator) then
            exit;
         services := locator.ConnectServer('.', 'root\CIMV2', '', '', 
'', '', 0, nil);
         if not Assigned(services) then
            exit;
         // fetch information about the active network cards
         networkConfigurations := services.ExecQuery('select 
MACAddress,IPAddress from Win32_NetworkAdapterConfiguration where 
IPEnabled=True', 'WQL', 0, nil);
         if not Assigned(networkConfigurations) then
            exit;

         networkCards := networkConfigurations._NewEnum as IEnumVariant;

         // iterate through all network cards
         while networkCards.Next(1, tempObj, tempVal) = S_OK do
         begin
              obj := IUnknown(tempObj) as ISWbemObject;

              vals := obj.Properties_.Item('MACAddress', 0).Get_Value;
              if VarIsNull(vals) then
                 continue;

              s := vals + '=';

              // ip addresses are an array of variants:
              vals := obj.Properties_.Item('IPAddress', 0).Get_Value;
              if VarIsArray(vals) then
              begin
                   for i := 0 to VarArrayHighBound(vals, 1) - 1 do
                       s := s + VarToStrDef(vals[i], '') + ',';

                   s := s + VarToStrDef(vals[VarArrayHighBound(vals, 
1)], '');
              end
              else if VarIsStr(vals)
              then
                  s := s + VarToStrDef(vals, '');

              Result.Add(s);
         end;
      except
            FreeAndNil(Result);

            raise;
      end;
end;
begin
      CoInitializeEx(nil, COINIT_MULTITHREADED);
      try
         // this call ensures that all interfaces
         // are cleared before unitialization
         Result := ExtractList;
      finally
             CoUninitialize;
      end;
end;
0
Michael
5/6/2009 1:04:17 PM
> Thank you very much. ^_^
> I success ! Code is as below.

Glad it worked, though just a couple things - 

>   function GetIfTable( pIfTable: PTMibIfTable; pdwSize: PULONG;
> bOrder: boolean ): DWORD;  stdCall; external 'IPHLPAPI.DLL';
> function GetIpAddrTable( pIpAddrTable: PTMibIPAddrTable;  pdwSize:
> PULONG;  bOrder: BOOL ): DWORD; stdcall; external 'IPHLPAPI.DLL';

As I said before, check out whether this should be BOOL or Boolean,
since those types have different sizes.  Normally it would be BOOL for
a WinAPI function, though IPHLPAPI.DLL may be different.

> function GetIPMAC: String;
> var
>   MibArr : TMIBIfArray;
> //  IP : String;
> //  Mac : String;
>   IP : AnsiString;
>   Mac : AnsiString;

Undo that change, since you assign the vars in question to function
results of type 'string'.  While the roundtrip is harmless, it is also
a waste.

>   Num:=StrToInt(IntToStr(NumEntries))-1;

Again, there's no need to convert a number to a string if you are going
to immediately convert it back to a number:

  Num := NumEntries - 1;
0
Chris
5/6/2009 2:29:37 PM
<ICST ICST> wrote in message news:113242@forums.codegear.com...

> The Code below can get correct answer on Delphi 7,
> but  get error answer on Delphi 2009.

You did not update your code to take into account that D2009 uses Unicode 
now.  You need to change the TMibIfRow record to use Byte instead of Char 
for its bDescr member, and you need to change the Get_IfTableMIB() and 
Get_IPAddrTableMIB() functions to use PAnsiChar or PByte instead of PChar 
for their pBuf variables.

-- 
Remy Lebeau (TeamB)
0
Remy
5/6/2009 4:30:20 PM
Reply:

Similar Artilces:

Delphi 7 to Delphi 2009 conversion
Hello group, What do I need to do to comile the following code in D2009. Compiler error after the Else E2010: Incompatible Types 'AnsiChar' and 'Char' if isUnicode then SearchHandle := FindFirstFilew( PWideChar( fn ), FindDataW ) else SearchHandle := FindFirstFile( PAnsiChar( Ansistring( fn ) ), FindDataA ); <<<<<compiler error in the above line >>>>>>>>>>> Regards, Bryan > What do I need to do to comile the following code in D2009. > Compiler error after the Else > E2010: Incompati...

Using Delphi 7 and Delphi 2010
I had a project in Delphi 7. I worked on it in Delphi 2010. When I try to open the .dpr again in Delphi 7, the IDE toolbar widens across both monitors, and Delphi 7 locks up. It appears that Delphi 2010 modifies the .dpr in a way that makes Delphi 7 unable to open it again. All my forms & units appear to open fine in D7 after D2010, except for the warnings on the ExplicitHeight and ExplicitWidth properties being missing... I can easily recreate the .dpr, but is this expected behavior? Thanks. Tom Field wrote: > I had a project in Delphi 7. > > I worked o...

I wrote an application and used cracked delphi 7, after i bought delphi 7
I wrote an application and used cracked delphi 7, I sold it, after i bought delphi 7 and recompiled application, is now my application legal or? > {quote:title=Ivan Ivanov wrote:}{quote} > I wrote an application and used cracked delphi 7, I sold it, after i bought delphi 7 and recompiled application, is now my application legal or? "I embezzled some money from my employer, returned the funds, and then got it back as a bonus. Can I still be arrested?" Uhhh .... didn't you just confess to a crime? > {quote:title=Ivan Ivanov wrote:}{quote} > I wrote an appli...

Can delphi 2009 and delphi 7 be on the same computer?
Can I install and run delphi 2009 and delphi 7 separately on the same computer or will they interfer with each other? I have delpi 7 already so do I need to choose a new folder (not c:\Borland) when installing 2009? Lorne Anderson wrote: > Can I install and run delphi 2009 and delphi 7 separately on the same > computer or will they interfer with each other? > > I have delpi 7 already so do I need to choose a new folder (not c:\Borland) > when installing 2009? It works fine. You usually want to install the older version first. As for folders, the root folde...

Convert Delphi 7 to Delphi 2009 [Edit]
Hi! Please, I have a code done in Delphi 7... Now I want to convert Delphi 7 to Delphi 2009 but I'm having problems when compile the code. Error message: +[DCC Fatal Error] Far.dpr(9): F2063 Could not compile used unit 'System.pas'+ Please can somebody help me? Source Download (349KB): http://rapidshare.com/files/256191328/FileManager.rar.html Mirror Source Download: http://www.megaupload.com/?d=12GYLPT0 Password: delphi Thank u so much! (sorry for my bad english, it is not my native language) Edited by: loquax loquax on Jul 15, 2009 12:24 PM Sorry, bu...

Code Porting
Hi people, Basically, I am moving an app from Delphi 5 to Delphi 2009 which is all great (yeah right!) and I am having a couple of issues with some thirdparty components that we have the source code for. Being that I wanted to make the task as easy as possible, I was able to download the component in Delphi 2007 format. I have now managed to port that to 2009 so it compiles only with warnings and no errors. So all is good at this moment. Now I am trying to install the component into the IDE by using the install menu option from the project manager. This is where I run into errors. ...

Question about Delphi 2009 vs Delphi 7
Hi, I was wondering if any of you can point me to a URLs that show the most important improvements between these versions of Delphi. The objective is convincing the powers-that-pay-the-bills that moving to D2009 (that we'd have to purchase) is a better idea than moving to D7 (for which we have licenses). Fire at will! -- Saluti, Alessandro Federici ------------------------------- "I have been through some terrible things in my life, some of which actually happened." (Mark Twain) Alessandro Federici wrote: > Hi, > I was wondering if any of yo...

How to use TIdStack to Get IP by Delphi 2009 ?
uses IdStack; function GetAllIP:String; var Ids: TIdStack; begin Ids := TIdStack.Create // Failed in Delphi 2009, How to fix ? try Result := Ids.LocalAddresses.Text; finally Ids.Free; end; end; procedure TForm1.FormCreate(Sender: TObject); begin Memo1.Lines.Add(GetAllIP); end; <ICST ICST> wrote in message news:112914@forums.codegear.com... > Ids := TIdStack.Create // Failed in Delphi 2009, How to fix ? TIdStack is an abstract base class. Do not instantiate it directly. Use the global GStack variable instead. Call the TIdStack.I...

Delphi 7.0 code convert to delphi XE ...
Hello All, I create an application using Web Server Application then CGI stand alone... In WebModule I add ModuleController component and IWPageProcedure... Below is my code in Delphi 7.0, this is how to call another units in webmodule... .... .... procedure TWebModule1.proMainGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmMain.Create(AWebApplication); end; procedure TWebModule1.proLogInGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmLogIn.Create(AWebA...

can i use delphi 2007 bpls in delphi 2009
can i use delphi 2007 bpls in delphi 2009 ? "Gaetan SIRY" skrev i meddelelsen news:8703@forums.codegear.com... > can i use delphi 2007 bpls in delphi 2009 ? No. -- Finn Tolderlund The compatiblity between D2006 and D2007 was unique. Normaly they can't be compatible because new version enhance/change the API. And D2009 defines String = Unicode where older version has String = Ansistring so D200x/Dx-BPL are 200% incompatible with D2009. ...

Code works in Delphi 7 but not in Delphi 2010 [Edit]
hello, i have a procedure that open's a file by passing the file name as the parameter to the executable. something like this {code} C : \ P r o g r a m F i l e s \ Da c k e r \ D r a c k e r . e x e " G : \ D E l p h i 7 \ D e l p h i 7 A p p _ l o g . t " {code} The source code is {code} procedure OpenFileWithExe var hReg: HKEY; Ret: Longint; RegDataType, RegDataSize: DWORD; CmdLine: array [0..560] of Char; Len: Integer; SInfo: TStartupInfo; PInfo: TProcessInformation; begin Ret := windows.RegOpenKeyEx(HKEY_CURRENT_USER, ...

Is possible to install delphi 7 and delphi 2009 upgrade?
I have delphi 7 interprise installed on my PC. Our company bought a delphi 2009 professional (upgrade). All of our projects now are made in delphi 7. We don't have time to move those projects to delphi 2009. Now, we are planning to create a new project using delphi 2009. Is it possible to install delphi 2009 in different windows profile without affecting delphi 7 projects? Edwin Aceron wrote: > I have delphi 7 interprise installed on my PC. Our company bought a > delphi 2009 professional (upgrade). All of our projects now are made > in delphi 7. We don't have time to move...

Is it worth to move my code from Delphi 2009 to Delphi 2010?
Hi guys, we are working on Delphi 2009 till this day because we do not have the time to upgrade our code to the newest version. There is always something more important (features, bugs...) and our code has 2+ million lines. I thought that instead of moving from D2009 to XE7 I could atleast move code to D2010 because it is more or less backward compatible and it shouldn't take me that much of a work. I wanted to ask you about your opinion. Is it a good version to move to? Regards. Dimitrij wrote: > I thought that instead of moving from D2009 to XE7 I could atleast > move ...

Delphi 4 to Delphi 2009
Hello, Thanks to all who answered my previous question. That was a great help. And atlast our client agreed to upgrade our delphi version from 4 to Delphi 2009. *Sigh*. But before that, I need to give the estimation and cost regarding the migration to delphi 2009. Can anyone tell me is there any tool to migrate from delphi 4 to delphi 2009 or just I need to compile our Delphi 4 application in Delphi 2009. I have read from the delphi 2009 feature matrix that Delphi 1 through Delphi 2007 import is possible in delphi 2009. But i am not that sure considering the size of our application. ...

Web resources about - How to fix get IP-MAC pairs code below from Delphi 7 to Delphi 2009 ? - embarcadero.delphi.vcl.using

Mac App Store - IP Scanner Home
Get IP Scanner Home on the Mac App Store. See screenshots and ratings, and read customer reviews.

How To Fix Self-Assigned IP Addresses In Mac OS X [Video How-To]
Not being able to get online can be a frustrating problem. It can cost hours of time and test your patience. See, Mac OS X doesn't always work ...


How to set a Static IP Address on a Mac
How to set a Static IP Address on a Mac

Oz metadata proposal: no to IP addresses, yes to MAC address logging
ASIO spook-in-chief: it's like the phone book, really Australia's federal government continues to say its proposed (but not yet drafted) metadata ...

What is my IP? How to find your IP address on iPhone, Mac and Windows
An IP (Internet Protocol) address is a number exclusive to any online device you may have, be it iPhone, iPad, Mac or Windows laptop, which identifies ...

Get DNS Server IP Addresses from the Command Line in Mac OS X
Get DNS Server IP Addresses from the Command Line in Mac OS X

How to set a Manual IP address in Mac OS X
How to set a Manual IP address in Mac OS X

What is my IP Address? How do I get my external IP Address in Mac OS X?
What is my IP Address? How do I get my external IP Address in Mac OS X?

Resources last updated: 12/19/2015 4:25:50 PM