Re: MessageDlg jams screen update




Rob Kennedy wrote:
Just what I needed, Thanks.
Les

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

.