delphi - Bind TServerSocket to a specific IP address in C++ Builder (10.1.2) -


i still using deprecated tserversocket component.

i bind tserversocket specific ip. question has been asked before delphi in site: how bind tserversocket specific ip address

however couldn't make work in c++ builder.

my code is:

class serverwrapper : private tserversocket {  public:       serverwrapper();   private:  };   serverwrapper::serverwrapper()    : tserversocket (0) {     //--- }  serverwrapper* pserver =0;  //... //.. //.  // , in function:   pserver = new serverwrapper; pserver->address = "192.168.0.1" ; pserver->active = true; 

however doesn't compile. says: e2247 'tabstractsocket::address' not accessible

i using c++ builder 10.1.2 berlin way.

it doesn't work because did not translate delphi code c++ correctly.

for 1 thing, using private inheritance instead of public inheritance. public , protected members inherited tserversocket private in serverwrapper. delphi has no notion of protected/private inheritance, public inheritance.

but more importantly, delphi has notion of implicit friendship. within unit, classes have full access private/protected members of other classes declared in same unit. includes inherited protected members. delphi example in other question takes advantage of feature, declaring local helper class implicitly gain public access address property unit declares helper.

but c++ has no notion of implicit friendship. translate delphi example c++, have explicitly promote access protected address property.

a literal translation of delphi code in c++:

class tserversocketaccess : public tserversocket { public:     __property address;    // or:    // using tserversocket::address; };  ((tserversocketaccess*)serversocket1)->address = "192.168.0.1"; serversocket1->active = true; 

applied serverwrapper class, this:

class serverwrapper : public tserversocket { public:     serverwrapper();      __property address;    // or:    // using tserversocket::address; };  serverwrapper::serverwrapper()     : tserversocket (0) {     //--- }  serverwrapper* pserver = 0; //... pserver = new serverwrapper; pserver->address = "192.168.0.1"; pserver->active = true; 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -