Rob,
The GetRadioGroupIndexAt function works perfectly, and is more
straightforward to use than your other suggestion, at least to my way
of thinking. Thank you very much - you've saved me hours of having to
recode and test things, in addition to adding the FindVCLWindow
function - which I had never heard of - to my toolbag. I'm still
surprised that I wasn't able to find any information on this subject in
my searches.
For the archives and in case anyone in the future has the same need,
here's how I got it to work (3 steps):
1. Assigned the PopMenu to the RadioGroup in the Object Inspector
2. Added Rob's GetRadioGroupIndexAt to the form:
function GetRadioGroupIndexAt(const Pos: TPoint): Integer;
var
Control: TWinControl;
Button: TRadioButton;
Group: TCustomRadioGroup;
begin
Result := -1;
Control := FindVCLWindow(Pos);
if not Assigned(Control) then
exit;
if not (Control is TRadioButton) then
exit;
Button := TRadioButton(Control);
if not (Button.Parent is TCustomRadioGroup) then
exit;
Group := TCustomRadioGroup(Button.Parent);
try
while True do begin
Inc(Result);
if Group.Buttons[Result] = Button then
exit;
end;
except
on EListError do
exit(-1);
end;
end;
3: Put the following code in the PopupMenu onPopUp event:
procedure TListenForm.Pop1Popup(Sender: TObject);
var
itemnum : integer;
mpos : TPoint;
begin
GetCursorPos(mpos);
itemnum := GetRadioGroupIndexAt(MPos);
//do something with itemnum
end;
--
Brad Blanchard
http://www.braser.com