Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.166 Beiträge
 
Delphi 12 Athens
 
#7

AW: Fokus wird nicht gesetzt

  Alt 22. Apr 2012, 19:37
Ein Bug?
Es gibt ja einmal den Fokus, welchen Delphi glaubt gesetzt zu haben und dann noch den Fokus, welcher beim WinControl wirklich aktiv ist.

Hab selber grade mit sowas zu kämpfen
http://www.delphipraxis.net/167825-p...gabefokus.html


Was sagt diese Variante?
Delphi-Quellcode:
procedure TForm4.Timer1Timer(Sender: TObject);
var
  S: string;
  H: HWND;
  C: TControl;
  B: array[0..MAX_PATH] of Char;
  i: Integer;
begin
  if Application.Active then S := 'Active else S := 'Inactive ';
  if Assigned(Screen.ActiveCustomForm) then
    S := S + Screen.ActiveCustomForm.ClassName + '.' + Screen.ActiveCustomForm.Name + ' ';
  if Assigned(Screen.ActiveForm) and Assigned(Screen.ActiveForm.ActiveMDIChild) then
    S := S + 'MDI:' + Screen.ActiveForm.ActiveMDIChild.ClassName + '.' + Screen.ActiveForm.ActiveMDIChild.Name + ' ';
  if Assigned(Screen.ActiveControl) then
    S := S + Screen.ActiveControl.ClassName + '.' + Screen.ActiveControl.Name + ' ';
  H := GetActiveWindow;
  C := FindControl(H);
  if not Assigned(C) then begin
    GetClassName(H, @B, MAX_PATH);
    S := S + '(' + B + ' ';
  end else
    S := S + '(' + C.ClassName + '.' + C.Name + ' ';
  H := GetFocus;
  C := FindControl(H);
  if not Assigned(C) then begin
    GetClassName(H, @B, MAX_PATH);
    S := S + B + ') ';
  end else
    S := S + C.ClassName + '.' + C.Name + ') ';

  Application.Title := S;
  for i := 0 to Screen.CustomFormCount - 1 do
    Screen.CustomForms[i].Caption := S;
end;

[add]
Statt deinem Hack würde ich es mal so probieren (in dem Timer)
Delphi-Quellcode:
if Application.Active then
  SetActive(Screen.ActiveControl.Handle);
bzw.
Delphi-Quellcode:
if Application.Active and (Screen.ActiveControl.Handle <> GetActive) then
  SetActive(Screen.ActiveControl.Handle);
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (22. Apr 2012 um 19:41 Uhr)
  Mit Zitat antworten Zitat