List Info

Thread: Re: changing formstyle at runtime




Re: changing formstyle at runtime
country flaguser name
United States
2007-08-09 07:34:27

i follow your code theo, but then i get the "cannot focus a disabled
or invisible window" error. if i remove the "Visible := True" then i
get this error "cannot make a visible window modal";. is there any
other solution?

thanks for all suggestions

__._,_.___
Recent Activity
Visit Your Group
SPONSORED LINKS
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Yoga Groups

Find Enlightenment

& exchange insights

with other members

Re: Re: changing formstyle at runtime
country flaguser name
Greece
2007-08-09 08:32:47
O/H reynaldi81 έγραψε:
> i follow your code theo, but then i get the
"cannot focus a disabled
> or invisible window" error. if i remove the
"Visible := True" then i

And what makes you believe that this "cannot
focus..." error
comes from your child form?

> get this error "cannot make a visible window
modal". is there any
> other solution?

Yes.

Code a bare-bone MDI project and apply my suggestion.
Do you get any error? Let me answer: No. I just done it
for you. Here it is.

main form code
---------------------------
uses
   f_Child;

procedure TMainForm.mnuNewClick(Sender: TObject);
var
   F : TForm;
begin
   F := TChildForm.Create(Self);
   F.Show;
end;

procedure TMainForm.mnuModalClick(Sender: TObject);
var
   F : TForm;
begin
   F := TChildForm.Create(Self);
   try
     F.ShowModal;
   finally
     F.Free;
   end;
end;

--------------------------------
child form code
--------------------------------
type
   TChildForm = class(TForm)
   public
     function ShowModal: Integer; override;
   end;

var
   ChildForm: TChildForm;

implementation

{$R *.dfm}



function TChildForm.ShowModal: Integer;
var
    OldFormStyle   : TFormStyle;
    OldBorderStyle : TFormBorderStyle;
begin
      OldFormStyle       := FormStyle;
      OldBorderStyle     := BorderStyle;
      try
        FormStyle    := fsNormal;
        BorderStyle  := bsDialog;
        Visible      := False;

        Result       := inherited ShowModal();
      finally
        FormStyle    := OldFormStyle;
        BorderStyle  := OldBorderStyle;
      end;	
end;

---------------------------------------

So the source of error is something else. Right?
IMHO, this famous "cannot focus..." error
comes from a window-control that your code, somehow,
tries to make it focused while it's not visible
or its parent is not visible or its parent's parent...
and so on.

That's because VCL's
   procedure TWinControl.SetFocus; { virtual; }
for some unknown to me reason (please VCL gurus
enlighten us here) omits window-type checks
before calling
   Windows.SetFocus(Handle)

For this reason I NEVER call
   ThisControl.SetFocus()
directly.

Instead I have the following functions.

function  CanFocus(Handle: THandle): Boolean; overload;
begin
   Result := Windows.IsWindow(Handle) and 
Windows.IsWindowVisible(Handle) and
Windows.IsWindowEnabled(Handle);
end;

function  CanFocus(Instance: TComponent): Boolean;
overload;
begin
   Result := Assigned(Instance) and (Instance is
TWinControl) and 
TWinControl(Instance).CanFocus and
CanFocus(TWinControl(Instance).Handle)
end;

function SetFocus(Instance: TComponent): Boolean;
begin
   Result := CanFocus(Instance);
   if Result then
     TWinControl(Instance).SetFocus();
end;


So try to find what is the control that causes the
error and make it focused by calling my SetFocus()
global function.


Please, let me know the result.


-- 
Regards
Theo

------------------------
Theo Bebekis
Thessaloniki, Greece
------------------------
Greek_Delphi_Prog : a Delphi Programming mailing list in
Greek at
    http:
//groups.yahoo.com/group/Greek_Delphi_Prog

CSharpDotNetGreek : A C# and .Net mailing list in Greek
language at
    http:
//groups.yahoo.com/group/CSharpDotNetGreek

atla_custom : a Unisoft Atlantis Customization mailing list
at
    http://grou
ps.yahoo.com/group/atla_custom
------------------------


-----------------------------------------------------
Home page: http://group
s.yahoo.com/group/delphi-en/
To unsubscribe: delphi-en-unsubscribe@yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://group
s.yahoo.com/group/delphi-en/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://g
roups.yahoo.com/group/delphi-en/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:delphi-en-digest@yahoogroups.com 
    mailto:delphi-en-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    delphi-en-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )