Borland c++: Error while assigning OnChange to another function?

142 views Asked by At

I'm tring to assign OnChange function to another function like:

XComp->OnChange = SycnroChange(prgManVoltageSet_SB->Address);

but compiler gives that error: "Not allowed type."

What should I do? Cant i assign like this?

3

There are 3 answers

4
marom On

IIRC you can make assignments like that in the form ->onChange = xyz ; where xyz is another function (or member function) with proper signature. You can't bind arguments and things like that.

So you should change SynchroChange signature first (most event handlers require just a generic TObject *Sender) and then inside that function look for the prgManVoltageSet (unless can be casted from the parameter 'Sender', but I have not enough context for this)

0
Remy Lebeau On

You are calling SycnroChange() and assigning its return value to OnChange. The OnChange event expects a pointer to an object method that conforms to the signature of TNotifyEvent:

typedef void __fastcall (__closure *TNotifyEvent)(System::TObject* Sender);

SycnroChange() has a return value of void instead. Thus the error.

For what you are attempting, you will have to use a separate event handler method that internally calls SycnroChange():

__fastcall TGenerator::TGenerator(TComponent *Owner)
    : TForm(Owner)
{
    ...
    // FYI, you can assign this at design-time instead of in code...
    XComp->OnChange = &XComChanged;
    ...
}

void __fastcall TGenerator::XComChanged(TObject *Sender)
{
    SycnroChange(prgManVoltageSet_SB->Address);
}
1
cwfighter On

From what you have said, I have knew your intention is that you wanted to execute SycnroChange(prgManVoltageSet_SB->Address) when XComp changed. So I think you can use a callback function with boost::signal2::signal and boost::bind, such as boost::bind(&SycnroChange, this, _1). When XComp changed, you could call the callback(prgManVoltageSet_SB->Address) to trigger and get an int.I hope these can help you.