c++ - Static Object and how to create it -
i've got issue program, i'm working embarcadero xe8 c++ builder 32 bit.
when want use method read/write stuff plc (programmable logic controller, used communicating machines) object null
.
i have main form want create connection plc.
in main have this:
static ceasyplchandler *pplchandler;
in method on same page have:
long readwritetest(void) { unsigned long ulstart; plcsymboldesc *psymbols; unsigned long ulnumofsymbols = 0; int inumofvars = 2; int i; char **ppszvars = new char*[inumofvars]; (i=0; i< inumofvars; i++) ppszvars[i] = new char[255]; long lresult = result_failed; lresult = pplchandler->getallitems(&psymbols, &ulnumofsymbols); if (lresult == result_ok)
when debug, shows pplchandler = null
when check out ceasyplchandle
comes from, come page (which included library) , see these lines:
class plch_dll_decl ceasyplchandler : public cplchandler { public: ceasyplchandler(rts_handle hlogfile = rts_invalid_handle); ceasyplchandler(plcconfig *pplcconfig, plcdevicedesc *pdevicedesc, rts_handle hlogfile = rts_invalid_handle); ceasyplchandler(unsigned long ulid, char *pszinifile, rts_handle hlogfile = rts_invalid_handle); ceasyplchandler(char *pszplcname, char *pszinifile, rts_handle hlogfile = rts_invalid_handle); virtual ~ceasyplchandler(void); // see plcconfig.h defines of pszprotocol // e.g. #define plcc_dn_tcpip_l2route "tcp/ip (level 2 route)" virtual long connecttcpipviagateway(char *pszgatewayip, char *pszplcip, char *pszprotocol = plcc_dn_tcpip_l2route, int bmotorola = 0, int bloadsymbols = 1, unsigned long ultimeout = plchandler_use_default, unsigned long ulport = 1200); virtual long connectrs232viagateway(char *pszgatewayip, short sport, unsigned long ulbaudrate, int bmotorola = 0, int bloadsymbols = 1, unsigned long ultimeout = plchandler_use_default); virtual long connectrs232viagatewayex(char *pszgatewayip, short sport, unsigned long ulbaudrate, int bmotorola = 0, int bloadsymbols = 1, unsigned long ultimeout = plchandler_use_default, ext_rs232_paramstyp *pextparams = null); virtual long connecttcpipviaarti(char *pszplcip, char *pszprotocol = plcc_dn_tcpip_l2route, int bmotorola = 0, int bloadsymbols = 1, unsigned long ultimeout = plchandler_use_default, unsigned long ulport = 1200); virtual long connectrs232viaarti(short sport, unsigned long ulbaudrate, int bmotorola = 0, int bloadsymbols = 1, unsigned long ultimeout = plchandler_use_default); virtual long connecttosimulation(char *pszsdbfile, int bloadsymbols = 1, unsigned long ultimeout = plchandler_use_default); virtual long connectviagateway3(char *pszgatewayip, char *pszaddress, int bloadsymbols = 1, unsigned long ultimeout = plchandler_use_default); virtual long connectviagateway3ex(char *pszgatewayip, unsigned long ulport, char *pszaddress, int bloadsymbols = 1, unsigned long ultimeout = plchandler_use_default); virtual long connectviaarti3(char *pszaddress, int bloadsymbols = 1, unsigned long ultimeout = plchandler_use_default); virtual long connecttosimulation3(char *pszsdb3xmlfile, int bloadsymbols = 1, unsigned long ultimeout = plchandler_use_default); // attention: structure of service must known in detail! // erroneous service might cause crash of plc! // send own service plc , receive reply virtual long syncsendservice(/*[in]*/ unsigned char *pbysend, /*[in]*/ unsigned long ulsendsize, /*[out]*/ unsigned char **ppbyrecv, /*[out]*/ unsigned long *pulrecvsize); // send own service plc virtual long asyncsendservice(/*[out]*/ int *piinvokeid, /*[in]*/ unsigned char *pbysend, /*[in]*/ unsigned long ulsendsize, /*[in]*/ cplchandlercallback *pasyncservicecallback = null); // service reply virtual long asyncgetservicereply(/*[in]*/ int *piinvokeid, /*[out]*/ unsigned char **ppbyrecv, /*[out]*/ unsigned long *pulrecvsize, long *plserviceresult); // sessionid device services (only used gw3 , arti3) virtual unsigned long getdevicesessionid(void); };
so how can create object?
i added line :
pplchandler = new ceasyplchandler(rts_invalid_handle);
and unresolved external errors:
[ilink32 error] error: unresolved external 'ceasyplchandler::~ceasyplchandler()' referenced c:\users\bart\documents\embarcadero\studio\projects\realtest\win32\debug\unit1.obj
but these in other file? why can't use these?
as...the greek person name can't spell, correctly said, you're not initializing pointer. static or global simple variable (int, double, char , pointers) initialized 0, that's null
comes from.
in order initialize static object correctly, either need use pointer , new
or use static ceasyplchandler plchandler(rts_invalid_handle);
, construct object , save new subsequent delete
(saving memory leak)
from looks of however, you're missing actual shared library contains code ceasyplchandler object
(at least that's linker error tells me).
please remember that, if decide go automatic static object, you'll need access .
instead of ->
.
Comments
Post a Comment