"JohnC" <
XXXX@XXXXX.COM >wrote in message
Quote
The array controls have been given names consisting of
one alpha followed by an index.
I would suggest using the Tag property of each control for that instead.
You can store array indexes in it. That would clean up your code a bit, ie:
void __fastcall TJMCClusterTable::OnColorChipClick(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
TShape *Chip = (TShape*) Sender;
FSelectedCluster = (Table->TopRow - Table->FixedRows) + Chip->Tag;
RadioButtons[Chip->Tag]->Checked = true;
}
void __fastcall TJMCClusterTable::OnSelectCell(TObject *Sender, int
ACol, int ARow, bool &CanSelect)
{
FSelectedCluster = (ARow - Table->FixedRows);
RadioButtons[ARow - Table->TopRow]->Checked = true;
if( FOnCellSelect )
FOnCellSelect(ARow, ACol);
}
void __fastcall TJMCClusterTable::OnRadioButtonClick(TObject *Sender)
{
TRadioButton *Button = (TRadioButton*) Sender;
if( (Button->Checked) && (!Scrolling) )
{
FSelectedCluster = (Table->TopRow - Table->FixedRows) +
Button->Tag;
if( FOnClusterSelect )
FOnClusterSelect(FSelectedCluster);
}
}
Now, as for your original problem - it is an issue of input focus. When the
TRadioButton.Checked property is set to true programmably, an OnClick event
is triggered. When a TRadioButton receives input focus and it is not
currently Checked, its Checked property is set to true and the OnClick event
is triggered. By calling ShowMessage(), you are moving input focus away
from the UI and then back. When the dialog is closed, input focus is moved
back to the previously active control. TShape is not a windowed control, so
it cannot receive input focus at all. Your previously selected TRadioButton
receives the input focus again, and since it is no longer Checked (since the
TShape changed that), the previous TRadioButton fires its OnClick event
again.
Here is a very simply example to show you what is happening. Create a new
TForm, put two TRadioButtons and a TShape on it, and then run this code:
// assign this OnClick handler to both TRadioButton controls...
void __fastcall TForm1::RadioButtonClick(TObject *Sender)
{
TRadioButton *Button = (TRadioButton*) Sender;
if( ActiveControl )
ShowMessage(Button->Name + " Clicked\nActive Control: " +
ActiveControl->Name);
else
ShowMessage(Button->Name + " Clicked\nActive Control: none");
}
void __fastcall TForm1::Shape1MouseDown(TObject *Sender, TMouseButton
Button, TShiftState Shift, int X, int Y)
{
RadioButton2->Checked = true;
}
Click on RadioButton1, and then click on the TShape over and over. See what
happens?
Clicking on RadioButton1 gives it input focus and then ShowMessage() is
called. When the dialog is closed, RadioButton is given input focus again,
but it is already Checked so nothing further happens.
Clicking on the TShape next sets RadioButton2 to Checked, but RadioButton1
is still focused! TShape cannot accept input focus. RadioButton2's Checked
property is changed, so it triggers an OnClick event, calling ShowMessage().
When closed, input focus moves back to RadioButton1, setting it to Checked
and triggering its OnClick event.
You don't have this problem when clicking on the TStringGrid because it is a
windowed control and thus accepts input focus. Clicking on the grid may
change a RadioButton's Checked property, thus calling ShowMessage(), but
input focus was moved to the grid first, and when ShowMessage() closes then
input focus is moved back to the grid, not any of the RadioButton controls.
You also don't have this problem when you are not calling ShowMessage() at
all (or if you use any other windowed control besides TShape) because input
focus is not being moved around the RadioButton controls in that situation.
If you want to debug your code in real-time without using popup messages,
you can use DebugOutputString() for that. You can send text messages to the
IDE De{*word*81}'s Event Log, or to an external debug logger, such as
SysInternals' DebugView, when not running your app inside the IDE.
Gambit