Accessing Methods of Components within a Component
Hello Everyone,
Just when I thought I was beginning to understand this, well... I am trying
to write a component which uses an Indy TCP Client component. My thought was
to have my component have a public/published method which in turn would
call the TIdTCPClient->Connect() method. My attempt at doing this compiles
and installs the component OK, but when I call this method from an
application I get access violations. Attached is a subset of the component
and header. Any help would be greatly appreciated. Thanks.
//--------------My_Client.h
file---------------------------------------------
#ifndef My_ClientH
#define My_ClientH
//--------------------------------------------------------------------------
-
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include "IdComponent.hpp"
#include "IdTCPClient.hpp"
#include "IdTCPConnection.hpp"
//--------------------------------------------------------------------------
-
class PACKAGE My_Client : public TCustomPanel
{
private:
TTimer *WatchDogTimer;
TTimer *Timer1;
protected:
public:
TIdTCPClient *IdTCPClient1;
__fastcall My_Client(TComponent* Owner);
void __fastcall Timer1Event(TObject *Sender);
void __fastcall WatchDogEvent(TObject *Sender);
void __fastcall OneShot(TObject *Sender);
__published:
//--------------------------------------------------------------------------
-
#endif
//------------My_Client.cpp
file-----------------------------------------------
#include <vcl.h>
#include "IdComponent.hpp"
#include "IdTCPClient.hpp"
#include "IdTCPConnection.hpp"
#pragma hdrstop
int Coun{*word*53}chDogs = 0, Count = 0, data[38];
AnsiString logDate, logTime;
bool OneShotFlag = false;
#include "My_Client.h"
#pragma package(smart_init)
//--------------------------------------------------------------------------
-
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(My_Client *)
{
new My_Client(NULL);
//--------------------------------------------------------------------------
-
__fastcall My_Client::My_Client(TComponent* Owner)
: TCustomPanel(Owner)
{
TIdTCPClient *IdTCPClient1 = new TIdTCPClient(Owner);
IdTCPClient1->Host = "127.0.0.1";
IdTCPClient1->Port = 6000;
IdTCPClient1->OnConnected = ConnectedEvent;
WatchDogTimer = new TTimer(this);
WatchDogTimer->Interval = 5000;
WatchDogTimer->Enabled = false;
WatchDogTimer->OnTimer = WatchDogEvent;
Timer1 = new TTimer(this);
Timer1->Interval = 1000;
Timer1->Enabled = false;
Timer1->OnTimer = Timer1Event;
//--------------------------------------------------------------------------
-
void __fastcall My_Client::OneShot(TObject *Sender)
{
IdTCPClient1->Connect();
OneShotFlag = true;
//--------------------------------------------------------------------------
-
namespace My_client
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(My_Client)};
RegisterComponents("AARE", classes, 0);
}
//--------------------------------------------------------------------------
-