Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: TWebBrowser Visible property does not seem to work


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Jul 13, 2017 2:44 PM Last Post By: Dan Barclay
Cornelia von Sc...

Posts: 7
Registered: 11/4/16
TWebBrowser Visible property does not seem to work  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 13, 2017 10:05 AM
I am using a TWebBrowser control to display a web page.
Under certain circumstances I do not want the webpage to show and just submit webpage data behind the scenes.
I have tried setting the Visible property on the TWebBrowser property to False, but the control with the webpage still shows.

GetCreditCardPage := TWebBrowser.Create(frmParent);
GetCreditCardPage.Visible := False;
TWinControl(GetCreditCardPage).Parent := frmParent;
GetCreditCardPage.Align := alNone;// alClient makes it go on top of the parent form and the same size as the parent form
if assigned(GetCreditCardPage) then
begin
GetCreditCardPage.Navigate('C:\AdagioSource\d10\AR\source\GetCardScreen.html');
GetCreditCardPage.OnCommandStateChange := GetCreditCardPageCommandStateChange;
GetCreditCardPage.OnNavigateError := GetCreditCardPageNavigateError;
end
else
begin
Result := APS_VC_STEP_TWO_NO_FORM;
EXIT;
end;
....

I finally replaced the
GetCreditCardPage.Visible := False;
by
GetCreditCardPage.Width := 0;
GetCreditCardPage.Height := 0;

and this did the trick, but I am wondering if I am missing something or if Visible property not working is a known Delphi bug.
Thanks
Cornelia

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: TWebBrowser Visible property does not seem to work  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 13, 2017 2:09 PM   in response to: Cornelia von Sc... in response to: Cornelia von Sc...
El 13/07/2017 a las 19:05, Cornelia von Schellwitz escribió:
I am using a TWebBrowser control to display a web page.
Under certain circumstances I do not want the webpage to show and just submit webpage data behind the scenes.
I have tried setting the Visible property on the TWebBrowser property to False, but the control with the webpage still shows.

Try this:

procedure ShowOleControl(Ctrl: TOleControl; Visible: Boolean);
var
   IPO: IOleInPlaceObject;
   Wnd: HWND;
begin
   if Succeeded(Ctrl.DefaultDispatch.QueryInterface(IOleInPlaceObject, IPO)) then
   begin
     if Succeeded(IPO.GetWindow(Wnd)) then
     begin
       if Visible then
           ShowWindow(Wnd, SW_SHOW)
         else
           ShowWindow(Wnd, SW_HIDE);
     end;
   end;
end;


Call the funcion like this to hide the webbrowser:
    ShowOleControl(GetCreditCardPage, False);


Call the funcion like this to show the webbrowser:
    ShowOleControl(GetCreditCardPage, True);
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: TWebBrowser Visible property does not seem to work  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 13, 2017 2:41 PM   in response to: Cornelia von Sc... in response to: Cornelia von Sc...
Cornelia von Schellwitz wrote:
I am using a TWebBrowser control to display a web page.
Under certain circumstances I do not want the webpage to show and just submit webpage data behind the scenes.
I have tried setting the Visible property on the TWebBrowser property to False, but the control with the webpage still shows.

GetCreditCardPage := TWebBrowser.Create(frmParent);
GetCreditCardPage.Visible := False;
TWinControl(GetCreditCardPage).Parent := frmParent;
GetCreditCardPage.Align := alNone;// alClient makes it go on top of the parent form and the same size as the parent form
if assigned(GetCreditCardPage) then
begin
GetCreditCardPage.Navigate('C:\AdagioSource\d10\AR\source\GetCardScreen.html');
GetCreditCardPage.OnCommandStateChange := GetCreditCardPageCommandStateChange;
GetCreditCardPage.OnNavigateError := GetCreditCardPageNavigateError;
end
else
begin
Result := APS_VC_STEP_TWO_NO_FORM;
EXIT;
end;
....

I finally replaced the
GetCreditCardPage.Visible := False;
by
GetCreditCardPage.Width := 0;
GetCreditCardPage.Height := 0;

and this did the trick, but I am wondering if I am missing something or if Visible property not working is a known Delphi bug.


I've tried various things in the past. Some controls seem to care about sizes and such. The most reliable I've found is to place it outside the view:

GetCreditCardPage.Top:= - GetCreditCardPage.height

You can bias it a little farther outside in case there are some browser edge effects.

GetCreditCardPage.Top:= - GetCreditCardPage.height -50

It looks like a very ugly way to do it, but it works well.

Edit: I've used this when I placed the TWebBrowser it its own window and moved the window, but it should also work on the TWebBrowser itself.

Dan

Edited by: Dan Barclay on Jul 13, 2017 4:43 PM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02