Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: using or selecting different func aside from the default constructor func


This question is answered.


Permlink Replies: 5 - Last Post: Feb 12, 2018 7:00 PM Last Post By: roca robin Threads: [ Previous | Next ]
roca robin

Posts: 140
Registered: 9/10/06
using or selecting different func aside from the default constructor func  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 11, 2018 11:16 AM
any link that would lead me into good understanding?

I tried google but it's not detailed, confusing.

I have already solve my issue or problem but I want to learn more!

//

Edited by: roca robin on Feb 11, 2018 3:21 PM

//

Problem Solved, works like a charm.
.
.
callerid = (INumberCaller*) new TNumberCaller->createNumberCaller11(1, 100.10); //select1
callerid = (INumberCaller*) new TNumberCaller->createNumberCaller22(12, 100.2, "Mansion New York", 2200);//select2
callerid = (INumberCaller*) new TNumberCaller->createNumberCaller33(123, 100.3, 3330); //select3
callerid = (INumberCaller*) new TNumberCaller->createNumberCaller44(1234, "Mansion New York", 4444); //select4
.
callerid->load(arrayofstring_for_loading);
//
callerid->draw(fimages, fnumbers);
//
callerid->save(arrayofstring_for_saving);
.
.

thanks to Alex, Ted and Reme

thank you guys,
my Delphi Phone Number Map Tracing is now done with c++ builder.

I hope I don't get bug, lol
roca robin

Posts: 140
Registered: 9/10/06
Re: using or selecting different func aside from the default constructor func  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 11, 2018 3:36 PM   in response to: roca robin in response to: roca robin
I solved my own issue/problem regarding to declaring multi constructor in c++ builder.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: using or selecting different func aside from the default constructor func
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 12, 2018 11:35 AM   in response to: roca robin in response to: roca robin
roca robin wrote:
callerid = (INumberCaller*) new TNumberCaller->createNumberCaller11(1, 100.10); //select1
callerid = (INumberCaller*) new TNumberCaller->createNumberCaller22(12, 100.2, "Mansion New York", 2200);//select2
callerid = (INumberCaller*) new TNumberCaller->createNumberCaller33(123, 100.3, 3330); //select3
callerid = (INumberCaller*) new TNumberCaller->createNumberCaller44(1234, "Mansion New York", 4444); //select4

That code is leaking memory. You are creating temporary TNumberCaller objects just to call non-static methods that in turn return new objects, and then you are not freeing the temp objects.

For what you are attempting to do, define multiple constructors with different parameters, don't use named methods, eg:

class TNumberCaller : public xCommon, public INumberCaller
{
public:
    __fastcall TNumberCaller(int param1, double param2); //select1
    __fastcall TNumberCaller(int param1, double param2, const String &param3, int param4);//select2
    __fastcall TNumberCaller(int param1, double param2, int param3); //select3
    __fastcall TNumberCaller(int param1, const String &param2, int param3); //select4
};
...
callerid = (INumberCaller*) new TNumberCaller(1, 100.10); //select1
callerid = (INumberCaller*) new TNumberCaller(12, 100.2, "Mansion New York", 2200);//select2
callerid = (INumberCaller*) new TNumberCaller(123, 100.3, 3330); //select3
callerid = (INumberCaller*) new TNumberCaller(1234, "Mansion New York", 4444); //select4


If you want to use named methods, they need to be declared as 'static', eg:

class TNumberCaller : public xCommon, public INumberCaller
{
public:
    __fastcall TNumberCaller(int param1, double param2, const String &param3, int param4);
 
    static _di_INumberCaller createNumberCaller11(int param1, double param2); //select1
    static _di_INumberCaller createNumberCaller22(int param1, double param2, const String &param3, int param4);//select2
    static _di_INumberCaler createNumberCaller33(int param1, double param2, int param3); //select3
    static _di_INumberCaller createNumberCaller44(int param1, const String &param2, int param2); //select4
};
...
_di_INumberCaller TNumberCaller::createNumberCaller11(int param1, double param2)
{
    return (INumberCaller*) new TNumberCaller(param1, param2, String(), 0);
}
 
_di_INumberCaller TNumberCaller::createNumberCaller22(int param1, double param2, const String &param3, int param4)
{
    return (INumberCaller*) new TNumberCaller(param1, param2, param3, param4);
}
 
_di_INumberCaler TNumberCaller::createNumberCaller33(int param1, double param2, int param3)
{
    return (INumberCaller*) new TNumberCaller(param1, param2, String(), param3);
}
 
_di_INumberCaller TNumberCallercreateNumberCaller44(int param1, const String &param2, int param2)
{
    return (INumberCaller*) new TNumberCaller(param1, 0.0, param2, param3);
}
...
callerid = TNumberCaller::createNumberCaller11(1, 100.10); //select1
callerid = TNumberCaller::createNumberCaller22(12, 100.2, "Mansion New York", 2200);//select2
callerid = TNumberCaller::createNumberCaller33(123, 100.3, 3330); //select3
callerid = TNumberCaller::createNumberCaller44(1234, "Mansion New York", 4444); //select4


--
Remy Lebeau (TeamB)
roca robin

Posts: 140
Registered: 9/10/06
Re: using or selecting different func aside from the default constructor func  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 12, 2018 5:34 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Yes, that's right?

on the second thought I have already do that, but I changed again,
because I thought that was not good, but it is? then I did wrong,
I will come back to that solution,

thank you so much, nice to think of that again.

but I see you have different other methods, then I'm following it.

Ok...
wait wait wait.... @Remy...

why there is di ?

don't use named methods, eg:

Edited by: roca robin on Feb 12, 2018 5:57 PM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: using or selecting different func aside from the default constructor func  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 12, 2018 6:42 PM   in response to: roca robin in response to: roca robin
roca robin wrote:
why there is di ?

It is from this:

typedef DelphiInterface<INumberCaller> _di_INumberCaller;


Interfaces are reference counted, where TInterfacedObject handles the actual reference counter, and destroys the object when the reference count falls to 0. You shouldn't return a raw interface pointer during object construction, that risks the caller forgetting to increment the reference count. It is better to return an object that ensures the reference count is managed correctly. DelphiInterface is one such class (there are many other similar classes, including TComInterface, CComPtr, com_ptr_t, etc).

--
Remy Lebeau (TeamB)
roca robin

Posts: 140
Registered: 9/10/06
Re: using or selecting different func aside from the default constructor func  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 12, 2018 7:00 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
roca robin wrote:
why there is di ?

It is from this:

typedef DelphiInterface<INumberCaller> _di_INumberCaller;


Interfaces are reference counted, where TInterfacedObject handles the actual reference counter, and destroys the object when the reference count falls to 0. You shouldn't return a raw interface pointer during object construction, that risks the caller forgetting to increment the reference count. It is better to return an object that ensures the reference count is managed correctly. DelphiInterface is one such class (there are many other similar classes, including TComInterface, CComPtr, com_ptr_t, etc).

--
Remy Lebeau (TeamB)

Got that, trying to implement,
I will try my best to follow your procedures, anytime for troubles there's someone here to help.

thank you soooooo much....
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02