절름발이 프로그래머/Delphi

GeoIP 데이터베이스를 Delphi 2009, 2010, XE에서 사용하는 방법

훅크선장 2011. 3. 15. 11:38
MaxMind 에서 http://www.maxmind.com/app/geolitecountry 통하여 제공하고 있는

IP를 소재 국가 및 도시로 바꾸어주는 Open Source API가 있습니다.

해당 API에 파스칼(Pascal) 이 지원되는데, 이 파일에 오래전에 만들어진 것이라서,

현재 RAD Studio 계열에서는 컴파일 에러가 발생합니다.

데이터베이스 파일은 그대로 사용합니다만,
제공되는 GeoIP.pas 소스 파일은 일부 수정이 필요합니다.

수정이 필요한 부분은 다음과 같이 두 부분입니다.
http://forum.maxmind.com/viewtopic.php?t=1204 에 있는 내용을 참고하였습니다.

1번 :

function TGeoIP._GetCity(IPNum: Cardinal; var GeoIPCity: TGeoIPCity): TGeoIPResult;
var
  ...
// p: PChar;
   p: PAnsiChar;
  ...


2번 :

function TGeoIP.AddrToNum(const IPAddr: string): Cardinal;
var
//netlong: LongInt;             // signed! - wrong type for comparison with INADDR_NONE
  netlong: Cardinal;            // unsigned   (or Longword)
begin
//netlong := inet_addr(PChar(IPAddr));
  netlong := inet_addr(PAnsiChar(AnsiString(IPAddr)));
  if netlong <> INADDR_NONE then