Topic: C++ Builder, How do I pass argument to Click Button

I am trying to run a function within C++ Builder when the user clicks a button. The function requires a pointer to a custom object as an argument. Is it possible to pass the argument to the button code.

ie: ThisRec is a pointer to an object how do I pass this as an argument to the button?

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  RefreshTable(ThisRec);
}

Re: C++ Builder, How do I pass argument to Click Button

Yes it is possible... don't fully understand what you mean though...

Re: C++ Builder, How do I pass argument to Click Button

Chacmool wrote:

Yes it is possible... don't fully understand what you mean though...

If I had a function called add that required two integer arguments, and returned an integer, its prototype would look like this:

int add(int a, int b)

to call this function I would use the following syntax:

add(1, 2)

this would return 3

Now if I wanted to pass an argument to a function in Builder (Button1Click in this case) is it possible to pass an argument directly (as oppose to picking up values from elsewhere. the reason I want to do this is to avoid having to use Global scope variables.

I have now actually recoded my program differently and now require to determine the name of the Sender variable passed to the Button1Click function. ie was it initiated from a Button Click or called from another area of the program. I know this is possible but don't know how to do it. Any Help appreciated.

Re: C++ Builder, How do I pass argument to Click Button

You can access the button-info from the Sender-pointer like this:

AnsiString caption = ((TButton*)Sender)->Caption

If you want to pass more stuff to the function add, just add it manually in the function, and don't forget to change the .h-file too.

Re: C++ Builder, How do I pass argument to Click Button

Chacmool wrote:

You can access the button-info from the Sender-pointer like this:

AnsiString caption = ((TButton*)Sender)->Caption

Thanks for that it works fine, although I could not access the caption property so I used the objects name instead ie:

AnsiString caption = ((TButton*)Sender)->Name

PM