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
[61024] Re:다음 델파이소스를 C++빌더로 변환 ...
김동원 [bandit21c] 1672 읽음    2010-05-11 17:20
컴파일은 해보지 않았습니다. 오타가 있을수도 있겠군요..
참고하시기 바랍니다.

=======================================================================================
//
// header file ...
//
typedef void __fastcall (__closure *TSearchURLEvent)(TObject *Sender, const String URL);
typedef void __fastcall (__closure *TURLErrorEvent)(TObject *Sender, const String URL, const String Msg);

class TWebRobot : public TThread
{
private:
    TIdHTTP    *        FHTTP;
    TURLErrorEvent    FURLErrorEvent;
    int                FSleepTime;
    TSearchURLEvent    FSearchURLEvent;
   
    void __fastcall UpdateURL(const String URL);
    void __fastcall UpdateError(const String Msg);
   
protected:
    void __fastcall URLCallback();
    void __fastcall ErrorCallback();
   
public:
    __fastcall TWebRobot();
    virtual __fastcall ~TWebRobot();
   
    String __fastcall GetURLText(const String URL);
   
public:
    __property int SleepTime = {read = FSleepTime, write = FSleepTime};
    __property TSearchURLEvent OnSearchURL = {read = FOnSearchURL, write = FOnSearchURL};
    __property TURLErrorEvent OnURLError = {read = FOnURLError, write = FOnURLError};
};

=======================================================================================
extern String CurrentURL;
extern String ErrorMsg;
extern RTL_CRITICAL_SECTION    CriticalSection;

//
// cpp file ....
//
String CurrentURL = "";
String ErrorMsg = "";
RTL_CRITICAL_SECTION    CriticalSection = {0, };

//----------------------------------------------------------------------------
__fastcall TWebRobot::TWebRobot() : TThread(true)
{
    FSleepTime = 3000;
    FHTTP = new TIdHTTP(NULL);
    FHTTP->Request->UserAgent = "DevBot";
    FHTTP->ReadTimeout = 10000;
    FreeOnTerminate = true;
    ::InitializeCriticalSection(&CriticalSection);
}
//----------------------------------------------------------------------------
__fastcall TWebRobot::~TWebRobot()
{
    FHTTP->Free();
    ::DeleteCriticalSection(&CriticalSection);
}
//----------------------------------------------------------------------------
void __fastcall TWebRobot::ErrorCallback()
{
    if(FURLErrorEvent)
        FURLErrorEvent(this, CurrentURL, ErrorMsg);
}
//----------------------------------------------------------------------------
String __fastcall TWebRobot::GetURLText(const String URL)
{
    try
    {
        UpdateURL(URL);
        Synchronize(URLCallback);
        return FHTTP->Get(URL);
    }
    catch(Exception &E)
    {
        UpdateError(E.Message);
        Synchronize(ErrorCallback);
        return "";
    }
}
//----------------------------------------------------------------------------
void __fastcall TWebRobot::UpdateError(const String Msg)
{
    ::EnterCriticalSection(&CriticalSection);
    try
    {
        ErrorMsg = Msg;
    }
    __finally
    {
        ::LeaveCriticalSection(&CriticalSection);
    }
}
//----------------------------------------------------------------------------
void __fastcall TWebRobot::UpdateURL(const String URL)
{
    ::EnterCriticalSection(&CriticalSection);
    try
    {
        CurrentURL = URL;
    }
    __finally
    {
        ::LeaveCriticalSection(&CriticalSection);
    }
}
//----------------------------------------------------------------------------
void __fastcall TWebRobot::URLCallback()
{
    if(FSearchURLEvent)
        FSearchURLEvent(this, CurrentURL);
}
//----------------------------------------------------------------------------

+ -

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