Solved

Trying to customize height and width of twebbrowser component

Posted on 2011-02-23
16
620 Views
Last Modified: 2012-05-11
Hi

I am trying to change some default values of the twebbrowser component and some succeed but especially the width and height will not succeed. Can anyone tell me why this fails?

The Align property works but the height and width do not
unit NullWebBrowser;

interface

uses
  SysUtils, Classes, Controls, OleCtrls, SHDocVw;

type
  TNullWebBrowser = class(TWebBrowser)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
   constructor Create(AOwner: TComponent); override;

  published
    property Width default 800;
    property Height default 500;
    property Align default alBottom;
  end;

procedure Register;

implementation

constructor TNullWebbrowser.Create(AOwner: TComponent);
   begin
    inherited Create(AOwner);
     Width := 800;
     Height := 500;
     Align := alBottom;
end;


procedure Register;
begin
  RegisterComponents('nullified', [TNullWebBrowser]);
end;

Open in new window

0
Comment
Question by:PeterdeB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
  • +2
16 Comments
 
LVL 8

Expert Comment

by:BdLm
ID: 34959236

I made a simple test with TWebbrowser :

     align and height width setting by placing directly on a form works fine , also for you ???
0
 
LVL 8

Expert Comment

by:BdLm
ID: 34959282
OK,  what di you pass in the create function as an argument ??


nil ???  that should not work
0
 
LVL 8

Expert Comment

by:BdLm
ID: 34959328
I copied your code and installed that component , worked fine as expected.....

do your create the BullWebbrowser at run time, if yes then show your code for that ....  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Expert Comment

by:jimyX
ID: 34959365
I am not sure but may be you need to create a wrapper from the TOleControl/TWinControl/TControl (I am just providing the properties you need to work with, it requires some work):
  TControl = class(TComponent)
  private
    FLeft: Integer;
    FTop: Integer;
    FWidth: Integer;
    FHeight: Integer;
    FAlign: TAlign;
    procedure SetAlign(Value: TAlign);
    procedure SetHeight(Value: Integer);
    procedure SetWidth(Value: Integer);
  public
    property Align: TAlign read FAlign write SetAlign default alNone; // default alBottom
  published
    property Width: Integer read FWidth write SetWidth; // default 800
    property Height: Integer read FHeight write SetHeight; // default 500
end;

procedure TControl.SetAlign(Value: TAlign);
var
  OldAlign: TAlign;
begin
  if FAlign <> Value then
  begin
    OldAlign := FAlign;
    FAlign := Value;
    Anchors := AnchorAlign[Value];
    if not (csLoading in ComponentState) and (not (csDesigning in ComponentState) or
      (Parent <> nil)) and (Value <> alCustom) and (OldAlign <> alCustom) then
      if ((OldAlign in [alTop, alBottom]) = (Value in [alRight, alLeft])) and
        not (OldAlign in [alNone, alClient]) and not (Value in [alNone, alClient]) then
        SetBounds(Left, Top, Height, Width)
      else
        AdjustSize;
  end;
  RequestAlign;
end;

procedure TControl.SetWidth(Value: Integer);
begin
  SetBounds(FLeft, FTop, Value, FHeight);
  Include(FScalingFlags, sfWidth);
end;

procedure TControl.SetHeight(Value: Integer);
begin
  SetBounds(FLeft, FTop, FWidth, Value);
  Include(FScalingFlags, sfHeight);
end;

constructor TControl.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FWidth:= 800;
  FHeight:= 500;
  FAlign:= [alNone, alTop, alBottom, alLeft, alRight, alClient, alCustom];
end;

Open in new window

0
 
LVL 3

Accepted Solution

by:
pasolo earned 500 total points
ID: 34959375
Try this, it may help

unit nullWebBrowser;

interface
uses
  SysUtils, Classes, Controls, OleCtrls, SHDocVw;

type
  TNullWebBrowser = class(TWebBrowser)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
   constructor Create(AOwner: TComponent); override;

  published
    property Width default 800;
    property Height default 500;
    property Align default alBottom;
  end;


implementation

constructor TNullWebbrowser.Create(AOwner: TComponent);
   begin
     inherited Create(AOwner);
     TwinControl(self).Parent := TwinControl(AOwner);
     TwinControl(Aowner).Width := 800;
     TWinControl(AOwner).Height := 500;
     Align := alClient;
     Navigate('http://www.microsoft.com');
end;

end.


unit browsertest;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw, NullWebBrowser, ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    procedure FormCreate(Sender: TObject);
  private
    wb1 : TNullWebBrowser;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
       wb1 := TNullWebBrowser.Create(panel1);
end;

end.
0
 
LVL 3

Expert Comment

by:pasolo
ID: 34959431
Since you want to align to bottom, you need to align the container to bottom, so the constructor will become:

constructor TNullWebbrowser.Create(AOwner: TComponent);
   begin
     inherited Create(AOwner);
     TwinControl(self).Parent := TwinControl(AOwner);
     TwinControl(Aowner).Width := 800;
     TWinControl(AOwner).Height := 500;
     TWinControl(AOwner).Align := alBottom;
     align := alClient;
     Navigate('http://www.microsoft.com');
end;
0
 

Author Comment

by:PeterdeB
ID: 34959728
@BdLm:yes they do. but I have to create around 35 of such projects all are different but the size of the webbrowser window is the same, that is why I wondered if I could make that happen automatically thanks for your fast reply
0
 

Author Comment

by:PeterdeB
ID: 34963855
@Bdsm: again thanks for your fast reply, I could not get much further though

@jimyX, I dont mind at all if I have to work for it, thanks for your reply, but it compiled with so many errors, i had a hard time fixing the first :(

@pasolo thanks for your reply too, your code compiled without errors, it is almost perfect but i need to place some edit controls on the form too, and the component i created with your code, takes up all of the form

Will you be willing to help me further so that the component does not take up all of the space, the align property is not required, just as long as it stays 800 x 500, and leaves space for other things

I have worked with your code and customized it and attached the sample

Again thanks for all the help and support here

Grtz
unit nullWebBrowser;

interface
uses
  SysUtils, Classes, Controls, OleCtrls, SHDocVw;

type
  TNullWebBrowser = class(TWebBrowser)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
   constructor Create(AOwner: TComponent); override;

  published
    property Width default 800;
    property Height default 500;
    property Align default alBottom;
  end;

procedure Register;

implementation

constructor TNullWebbrowser.Create(AOwner: TComponent);
   begin
     inherited Create(AOwner);
     TwinControl(self).Parent := TwinControl(AOwner);
     TwinControl(Aowner).Width := 800;
     TWinControl(AOwner).Height := 500;
     Align := alClient;
end;

procedure Register;
begin
  RegisterComponents('nullified', [TNullWebBrowser]);
end;


end.

Open in new window

0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 34964222

You are trying to adjust the size of the parent control automatically???
Not a good idea

     TwinControl(self).Parent := TwinControl(AOwner);
     TwinControl(Aowner).Width := 800;
     TWinControl(AOwner).Height := 500;


What if the OWner is not a TWinControl, What happens to this piece of code?
You will get an invalid cast.

You should at least try and test the owner type
The Owner may also not have properties for Width and Height, think about that

One more thing, the Owner is not always the Parent, Parent and Owner can be different
0
 
LVL 3

Expert Comment

by:pasolo
ID: 34964478
What I have done is place your TWebBrowser descendant inside a panel and resize it to 800x500..
The panel is inside your form, That leaves space in the form for other controls, like edit boxes, buttons or anything else. Of course you can place the panel inside other component, like other panel.

@ewangoya:
I know, but what I have done is required and owners are not parents of couse..
0
 

Author Comment

by:PeterdeB
ID: 34964914
Well the component almost works, and saves me lots of time adjusting the width and height of the browser window
0
 

Author Comment

by:PeterdeB
ID: 34968738
Pasolo sorrry i completely misssed your comment! Thanks
0
 

Author Closing Comment

by:PeterdeB
ID: 34968846
Thanks for fixing my issue
0
 

Author Comment

by:PeterdeB
ID: 34968857
I removed one line and it works perfectly
unit nullWebBrowser;

interface
uses
  SysUtils, Classes, Controls, OleCtrls, SHDocVw;

type
  TNullWebBrowser = class(TWebBrowser)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
   constructor Create(AOwner: TComponent); override;

  published
    property Width default 800;
    property Height default 500;
    property Align default alBottom;
  end;


implementation

constructor TNullWebbrowser.Create(AOwner: TComponent);
   begin
     inherited Create(AOwner);
     TwinControl(self).Parent := TwinControl(AOwner);
     TwinControl(Aowner).Width := 800;
     TWinControl(AOwner).Height := 500;
     Align := alClient;
end;

end.

Open in new window

0
 

Author Comment

by:PeterdeB
ID: 34968865
By the way it worked perfectly already but i removed the navigate line so it will not browse automatically
0
 
LVL 3

Expert Comment

by:pasolo
ID: 34969441
I put the navigation to see clearly where it was placed..
Enjot:)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question