C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[61008] 다음 델파이소스를 C++빌더로 변환 ...
정원철 [wiss] 1562 읽음    2010-05-10 11:05
아래의 델파이 소스를 빌더로 해보려는데 도무지 모르겠네요..
빌더 초보인데 고수님들 꼭 좀 도와주세요..-.-

unit WebRobot;

interface

uses
  Classes, SysUtils, Windows, IdURI, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP, IdAntiFreeze;

type
  TSearchURLEvent = procedure (Sender: TObject; const URL:string) of object;
  TURLErrorEvent = procedure (Sender: TObject; const URL, Msg:string) of object;


  TWebRobot = class(TThread)
  private
    FHTTP: TIdHTTP;
    FURLErrorEvent: TURLErrorEvent;
    FSleepTime: Integer;
    FSearchURLEvent: TSearchURLEvent;

    procedure UpdateURL(const URL: string);
    procedure UpdateError(const Msg: string);
  protected
    procedure URLCallback;
    procedure ErrorCallback;
  public
    constructor Create; virtual;
    destructor Destroy; override;
    function GetURLText(const URL: string): string;
  public
    property SleepTime: Integer read FSleepTime write FSleepTime;
    property OnSearchURL: TSearchURLEvent read FSearchURLEvent write FSearchURLEvent;
    property OnURLError: TURLErrorEvent read FURLErrorEvent write FURLErrorEvent;
  end;

var
  CurrentURL: string;
  ErrorMsg: string;
  CriticalSection: TRTLCriticalSection;

implementation

{ TWebRobot }

constructor TWebRobot.Create;
begin
  inherited Create(True);

  FSleepTime:= 3000;
  FHTTP:= TIdHTTP.Create(nil);
  FHTTP.Request.UserAgent:= 'DevBot';
  FHTTP.ReadTimeout:= 10000;
  FreeOnTerminate:= True;
// Priority := tpIdle;
  InitializeCriticalSection(CriticalSection);
end;

destructor TWebRobot.Destroy;
begin
  FHTTP.Free;
  DeleteCriticalSection(CriticalSection);
  inherited;
end;

procedure TWebRobot.ErrorCallback;
begin
  if Assigned(FURLErrorEvent) then
     FURLErrorEvent(self, CurrentURL, ErrorMsg);
end;

function TWebRobot.GetURLText(const URL: string): string;
begin
  Result:= '';
   try
     UpdateURL(URL);
     Synchronize(URLCallback);
     Result:= FHTTP.Get(URL);
   except
     on E: Exception do
     begin
       UpdateError(E.Message);
       Synchronize(ErrorCallback);
     end;
   end;
end;

procedure TWebRobot.UpdateError(const Msg: string);
begin
  EnterCriticalSection(CriticalSection);
  try
    ErrorMsg:= Msg;
  finally
    LeaveCriticalSection(CriticalSection);
  end;
end;

procedure TWebRobot.UpdateURL(const URL: string);
begin
  EnterCriticalSection(CriticalSection);
  try
    CurrentURL:= URL;
  finally
    LeaveCriticalSection(CriticalSection);
  end;
end;

procedure TWebRobot.URLCallback;
begin
  if Assigned(FSearchURLEvent) then
     FSearchURLEvent(self, CurrentURL);
end;

end.

+ -

관련 글 리스트
61008 다음 델파이소스를 C++빌더로 변환 ... 정원철 1562 2010/05/10
61024     Re:다음 델파이소스를 C++빌더로 변환 ... 김동원 1672 2010/05/11
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.