Re: MessageDlg jams screen update
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Sat, 26 Aug 2006 12:06:03 -0500
ellenjay1@xxxxxxxxxxx wrote:
I am having great difficulties with Message box stopping screen update
e.g
.procedure TForm1.FormActivate(Sender: TObject);
begin
Edit1.Visible:=True;
Edit1.SetFocus;
end;
procedure TForm1.Edit1DblClick(Sender: TObject);
begin
Edit1.Visible:=False;
End;
procedure TForm1.Edit1Exit(Sender: TObject);
begin
Label1.Visible:=True;
Label1.Caption:=Edit1.Text;
Application.ProcessMessages;
end;
works as expected.
BUT
Change to
procedure TForm1.Edit1Exit(Sender: TObject);
begin
Label1.Visible:=True;
Label1.Caption:=Edit1.Text;
Application.ProcessMessages;
{******************* }
GetOk;
{*******************}
end;
Procedure GetOk;
Begin
MessageDlg('Testing', mtInformation, [mbOK], 0);
end;
And Edit1 Remains Visible AND Label1 remains hidden until AFTER
MessageDlg is fired..
What am I missing?
Is there any way around this ?
Under no circumstances should you change the focus during a focus-changing event. During the OnExit event, the operating system is still in the process of switching the focus from one window to another. When you display a dialog box, you interrupt the normal sequence of focus-changing messages, and the controls involved in the original focus change get confused about whether they really have the focus. (One control might have focus, but another control is displaying the caret, for instance.)
The way to solve this is to post a message to the form. Posted messages go to the end of the message queue, so they will arrive after any other pending focus-related messages have already been handled. In your OnExit event, post a message to your form, like this:
PostMessage(Handle, wm_EditFocusLost, 0, 0);
You can define wm_EditFocusLost as a constant in the unit's interface section:
const
wm_EditFocusLost = wm_User + 1;
Now write a message handler for that message. In your form's private section, declare a method like this:
private
procedure WMEditFocusLost(var Message: TMessage); message wm_EditFocusLost;
Now implement the method:
procedure TLesForm.WMEditFocusLost(var Message: TMessage);
begin
if GetOK then begin
Label1.Caption := Edit1.Text;
Edit1.Visible := False;
Label1.Visible := True;
end else Edit1.SetFocus;
end;
Under very few circumstances should you call Application.ProcessMessages. I don't see why you need it in this situation.
--
Rob
.
- Follow-Ups:
- Re: MessageDlg jams screen update
- From: CC
- Re: MessageDlg jams screen update
- From: ellenjay1
- Re: MessageDlg jams screen update
- References:
- MessageDlg jams screen update
- From: ellenjay1
- MessageDlg jams screen update
- Prev by Date: Re: how do i use the "Format %" ?
- Next by Date: Events in a console app
- Previous by thread: MessageDlg jams screen update
- Next by thread: Re: MessageDlg jams screen update
- Index(es):
Relevant Pages
|