Einzelnen Beitrag anzeigen

Delphi.Narium

Registriert seit: 27. Nov 2017
2.415 Beiträge
 
Delphi 7 Professional
 
#2

AW: sporadische Exceptions bei TForm.SetFocus

  Alt 28. Jul 2021, 10:17
SetFocus geht nur, wenn schon sichtbar.

Mach davor bitte mal noch ein Show. Dann sollte das Problem behoben sein oder zumindest reduziert.

Oder eventuell so?
Delphi-Quellcode:
procedure TRWForm.doMouseActivate(AControl: TControl);
begin
  if (not WinControlValid(Self)) or IsDestroying then
    Exit;
  FLastClickedControl := AControl;
  if (Self <> rwScreen.ActiveForm) then
  begin
    // Erstmal uns selbst zum aktiven Formular machen,
    rwScreen.ActiveForm := Self;
    // uns selbst anzeigen
    Show;
    // und dann erst den Focus setzen.
    try
      if (Visible and CanFocus) then
        SetFocus; // Hier wird Exception ausgelöst!
    except
      ///// Nur vorübergehend
    end;
  end;
end;
  Mit Zitat antworten Zitat