Yu shouldn't have that problem unless the second form (the modal one) is not closing correctly. But in that case your code wouldn't pass from the
if SecondFrm.ShowModal=MrOk then ....
Incidentally, this code:
MainFrm.Enabled:=true;
MainFrm.Visible:=true;
MainFrm.ActiveControl:=MainFrm;
shouldn't be necessary. Once the modal form is closed the focus should revert to the caller wiyhout more ado. In any case, the usual setting order is:
1) Visible,
2) Enabled (which shouldn't have changed) and
3) ... don't set ActiveControl = form: it's allowed, because a form is effectively a control, but trying to set focus to a form makes the form try to "pass the ball" to its "ActiveControl", if set. You can see where that would lead
There must be soemthing strange going on in your program because usually all that is needed is something like:
procedure TMainFrm.ButtonClick(Sender: TObject);
begin
if not Assigned(SecondFrm) then
SecondFrm := TSecondFrm.Create(Application);
if SecondFrm.ShowModal = mrOK then begin
{do something};
end;
end;
Can you show (or attach) a more complete example?