Delphi - Bring your Application to the top of the screen in Windows

I program in Delphi for the Windows environment, but the following should work in most modern programming languages with slight modifications.
Since Windows 98, the standard BringToFront() function no longer has the same power. When called, your application’s window remains where in is in the z-order, and the task button flashes.

I was asked to make our Emojic Text Editor have a Stay On Top feature.

The following event routine for a CheckBox was created:

procedure TMainForm.StayOnTopClick(Sender: TObject);
begin
Application.NormalizeTopMosts;
If StayOnTop.Checked then
begin
SetWindowPos(MainForm.Handle, HWND_TOPMOST, 0,0,0,0, SWP_NOACTIVATE+SWP_NOMOVE+SWP_NOSIZE);
end
else
SetWindowPos(MainForm.Handle, HWND_NOTOPMOST, 0,0,0,0, SWP_NOACTIVATE+SWP_NOMOVE+SWP_NOSIZE);
end;

That worked great until my application tried to save and open it’s own Modal Form. Then my Modal Form was locked away and inaccessible under my Topmost window.

So I placed the following around every set of instructions in each of my MenuItem’s Event routines:

procedure TMainForm.SaveMenuItemClick(Sender: TObject);
begin
SetWindowPos(MainForm.Handle, HWND_NOTOPMOST, 0,0,0,0, SWP_NOACTIVATE+SWP_NOMOVE+SWP_NOSIZE);
SaveFile;
StayOnTopClick(self);
end;

Basically I just turn the Stay On Top feature off until the Event is done, then I check to see if I intend to set the Stay On Top feature back on.