>> Okay last simple question - from a control how to I find its form?  so I
>> can get the Handle?
>> function getParentForm(wc:TwinControl):Tform;
>> var
>>   parentControl :TWinControl;
>> begin
>>   try
>>     parentControl := wc.Parent;
>>     while not ((parentControl is Tform) or (parentControl =nil)) do
>>       parentControl := parentControl.Parent;
>>     result := parentControl as Tform;
>>   except
>>     on E:exception do if wc<>nil then raise exception.create(
>>        'Failed to get parent form for '+wc.name+' Name : '+e.message);
>>   end;
>> end;

> But it seems a bit long winded

How's this then ... (admittedly doesn't provide the same side-effects as the above)

function FindControlForm(WC:TwinControl):Tform;
begin
  Result := nil;
  repeat
    if WC is TForm then Result := TForm(WC)
    else WC := WC.Parent;
  until WC=Result;
end;

> How does this compare with GetTopParentHandle or Screen.ActiveForm.Handle

These don't produce the same result necessarily do they? At least the wordiness
of the help implies otherwise for GetTopParentHandle and we couldn't be sure the
request was for the currently active form...

--
Aaron Scott-Boddendijk
Jump Productions
(07) 838-3371 Voice
(07) 838-3372 Fax


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to