Question

Webbrowser - Getting form elements in frames

Asked by: wildzero

Gidday there,

If I load a page and use
showmessage(IntToStr(WebBrowser.OleObject.Document.Forms.Length))
I get the number of forms on the page.
ie 1 or 2 ect

Now if that page has frames it always returns 0
How can I get the count of forms, or more importantly, how can I access a forms elements on a page with frames?
Like
WebBrowser.OleObject.document.forms.item(1).elements.item('myname').value:= 'Bob';

Cheers guys

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-11-19 at 19:21:34ID21214157
Topic

Delphi Programming

Participating Experts
3
Points
500
Comments
38

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. memory leak showmessage??!!
    unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; Button2: TButton; procedure Button2Click(Sender: TObject); procedure Button1C...
  2. IntToStr
    Just learning... I have an edit and would like to click on a button to add (numbers). Say edit is 0 at the beginning and when I click on a button it increases to 1 then another click..goes to two...etc...
  3. #include <> for IntToStr
    Hi; In a program I am writing, I would like to take a number of strings and ints and send them to an output stream for display. To make things easier, I would like to convert all of the ints to strings and I have seen that there is a function IntToStr that should do this for...
  4. showmessage
    I am using showmessage to help me develop a program. However, I am now showing a string which is very large... The parts of the string that I want to look at are off the page and I can not get to them? Is there a scrollable version of Showmessage? If not how best can I see th...
  5. Destroy a frame created dynamically
    I create a frame dynamically in a TabSheet, himself created dynamically... When I try to destroy the frame from a button placed on the Parent Tab, I got an "Abstract error"... Code follow... OldFrame3 and OldTab was well-assigned (pointed right). var x: integer; ...
  6. showmessage()
    hi i wanna write a message in 2 lines in Showmessage() how can i do that

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: wildzeroPosted on 2004-11-19 at 20:49:10ID: 12632146

Points upped

 

by: carrzkissPosted on 2004-11-19 at 22:25:24ID: 12632304

If you had a link that I could help test on that would be helpful.
But anyway, take a look at this code.
And see if you can accomplish what you need with it.

How t0 interate through Frames
=====================================
procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to (WebBrowser1.OleObject.Document.frames.Length - 1) do
    if WebBrowser1.OleObject.Document.frames.item(i).document.queryCommandEnabled('Copy') then
      ShowMessage('copy command is enabled for frame no.' + IntToStr(i));
end;
======================================
Carrzkiss

 

by: wildzeroPosted on 2004-11-19 at 23:17:17ID: 12632403

Carrzkiss,

Gidday there
Let me throw up a site - while I do that

If thats how to interate though frames, how could I use that to fill out a form on a frame?
like, interate though frames to interate though forms ;)

 

by: carrzkissPosted on 2004-11-19 at 23:19:57ID: 12632409

Put up a site, and send the link over, I will take a look at it.
Also, if you have some sample code that you are using to do it.
Without Frames, Then please post that as well.
This way we are both working on the same track.

Carrzkiss

 

by: carrzkissPosted on 2004-11-19 at 23:21:06ID: 12632410

Code for filling in the forms, it what I meant to say

 

by: wildzeroPosted on 2004-11-19 at 23:30:31ID: 12632423

http://storeit-online.com/framestest/index.html

There is a url there of something I am trying to do, just like fillin the fields of say, the main page (name and url)
I tried using this

For i := 0 to WebBrowser.OleObject.Document.Forms.Length-1 do
  begin
    WebBrowser.OleObject.document.forms.item(i).elements.item('name').value:= 'Bob';
    WebBrowser.OleObject.document.forms.item(i).elements.item(url).value:= 'http://mysite.com';
  end;


Even just showmessage(IntToStr(WebBrowser.OleObject.Document.Forms.Length));
which normally returns more then 0

 

by: wildzeroPosted on 2004-11-20 at 21:53:56ID: 12636917

Hey there, manage to get any further?

 

by: wildzeroPosted on 2004-11-21 at 12:32:53ID: 12639792

Figured it out! Finally

procedure TForm1.Button5Click(Sender: TObject);
var
  g, f, k : integer;
  pDispatch : IDISPATCH;
  textarea: IHTMLTextAreaElement;
begin
  for f := 0 to WebBrowser1.OleObject.Document.frames.Length - 1 do
    begin
      showmessage(intToStr(WebBrowser1.OleObject.Document.frames.item(f).document.Forms.Length));
        for g := 0 to WebBrowser1.OleObject.Document.frames.item(f).document.Forms.Length-1 do
          begin
             for k := 0 to WebBrowser1.OleObject.Document.frames.item(f).document.forms.item(g).elements.length-1 do
              begin
                showmessage(WebBrowser1.OleObject.Document.frames.item(f).document.forms.item(g).elements.item(k).name);
                showmessage(WebBrowser1.OleObject.Document.frames.item(f).document.forms.item(g).elements.item(k).tagname);
                showmessage(WebBrowser1.OleObject.Document.frames.item(f).document.forms.item(g).elements.item(k).type);
                {Fill text field}
                WebBrowser1.OleObject.Document.frames.item(f).document.forms.item(g).elements.item('name').value := 'Bob';
                {Fill in a text area}
                pDispatch := WebBrowser1.OleObject.Document.frames.item(2).document.forms.item(0).elements.item('S1', 0);
                  try
                    OleCheck(pDispatch.QueryInterface(IID_IHTMLTextAreaElement, textarea));
                    textarea.Set_value('Hello');
                  except
                  end;
              end;
          end;
    end;
end;

 

by: carrzkissPosted on 2004-11-21 at 13:21:57ID: 12639956

Hello WildZero;

  I am so sorry that I have not gotten back with you.
It has been rather hectic here at my house over the weekend.
And I just took a break from doing anything on the computer.
(The life of being a single parent)
I am glad to see that you was able to figure it out with the
Code that I sent over.

Maybe I am just wore out, But I cannot get it to compile.
Getting a few errors. ( Maybe rest will help my brain ;-)  )

[Error] Unit1.pas(34): Undeclared identifier: 'IHTMLTextAreaElement'
[Error] Unit1.pas(51): Undeclared identifier: 'OleCheck'
[Error] Unit1.pas(51): Undeclared identifier: 'IID_IHTMLTextAreaElement'
&
[Error] Unit1.pas(52): Missing operator or semicolon
On this:                     textarea.Set_value('Hello');

Anyway.
Hope that you make something that makes you a lot of fortune.

Take Care
Carrzkiss

 

by: EddieShipmanPosted on 2004-11-22 at 11:45:44ID: 12647875

Your errros come from missing units in your uses.
Be aware that you WILL NOT be able to do this on frames that are not on your the same domain as
the frameset. obtaining info from cross-domain frames will be caught by IE's security measures.

 

by: wildzeroPosted on 2004-11-22 at 11:50:47ID: 12647942

MSHTML_TLB (MSHTML for some) and SHDocVw I think it is you need.

Eddie, you are right - and thats the thing I need to work nothing you can think of/suggest?

 

by: carrzkissPosted on 2004-11-22 at 13:03:29ID: 12648730

Uses MSHTML_TLB, SHDocVw, ComObj;

Thanks, good now I can test it out.

 

by: EddieShipmanPosted on 2004-11-23 at 12:42:54ID: 12659182

I can't get that code to work at all.

 

by: carrzkissPosted on 2004-11-23 at 12:51:40ID: 12659263

I have not had the opertinity to test it out.
Got so much more stuff going on that I forgot about it.

I do know that I compiled the project, but that was as for as I got with it.
I could not feel in anything on the forms?
Will have to test it out again later on.

Carrzkiss

 

by: AqueathPosted on 2004-11-25 at 09:48:38ID: 12676293

Hi,
"WebBrowser1.OleObject.Document.frames.item(0).Document.forms.Item(0).Item(0).Value:='Bob';" will set the value of the first item on the first form of the first frame to 'Bob' provided that  such an item, form and frame exist, and provided that the item can be set.

Hope that helps you.

A.

 

by: AqueathPosted on 2004-11-25 at 10:14:50ID: 12676433

 

by: EddieShipmanPosted on 2004-11-29 at 06:51:33ID: 12696390

Aqueath,
  It doesn't work on ;ater versions of IE6 because of cross-domain security.
I can't even get it to work when the frame is on my own domain.

 

by: AqueathPosted on 2004-11-29 at 12:21:10ID: 12699872

Eddie,
According to Windows Update I have upgraded to the latest version of IE6, and this still works on my machine. I did however use the TWebBrowser component while testing this. Can you list the page you tried this on? And you IE6 version?

A.

 

by: wildzeroPosted on 2004-11-29 at 12:34:48ID: 12700004

A.

I got the code I posted to work fine but doesn't with cross domain things.
ie one frame on a different domain name.

Did you try that?
I am running IE6 on both machines

 

by: EddieShipmanPosted on 2004-11-29 at 12:38:00ID: 12700033

I tried it both ways and couldn't get it to work in either situation.

Here is the HTML I used:
<html>
  <head>
    <title>Untitled Document</title>
  </head>
  <frameset rows="14.3%,*,12.3%" frameborder="NO" border="1" framespacing="0">
    <frame src="gallery_2.html" name="topFrame" scrolling="NO" noresize frameborder="no" border="0">
      <frameset cols="27%,70%" frameborder="no" border="1" framespacing="0" marginwidth=0 marginheight=0>
        <frame src="gallery_3.html" name="mainFrame" scrolling="NO" noresize>
        <frame src="http://www.delphipages.com" name="dynamicframe" scrolling="yes" noresize frameborder="yes">
      </frameset>
    <frame src="gallery_4.html" name="topFrames" scrolling="NO" noresize frameborder="no">          
  </frameset>
</html>

The gallery_X.html pages are pages on my site.

If I change the delphipages.com url to another page on my site, it still doesn't work.

Of course I'm also trying this locally, too, (http://locahost/framsettest.html) and it doesn't work in either case.

 

by: wildzeroPosted on 2004-11-29 at 12:50:05ID: 12700134

With
WebBrowser1.OleObject.Document.frames.item(0).Document.forms.Item(0).Item(0).Value:='Bob';
I get Access Denied.

When I do this
  showmessage(IntToStr(WebBrowser1.OleObject.Document.frames.Length));
  for f := 0 to WebBrowser1.OleObject.Document.frames.Length - 1 do
    showmessage(intToStr(WebBrowser1.OleObject.Document.frames.item(f).document.Forms.Length));

I get the first message (2 for two forms)
But then I get a access denied message as well.....

 

by: AqueathPosted on 2004-11-29 at 12:52:41ID: 12700163

Wildzero,
Can you tell me the url of the page you're trying to reach?

A.

 

by: wildzeroPosted on 2004-11-29 at 13:07:11ID: 12700277

I just tried this and got the same result.

Open up notepad and paste this

<html>
  <head>
    <title>Untitled Document</title>
  </head>
  <frameset rows="595,*,115" frameborder="NO" border="1" framespacing="0">
   <frame src="http://www.delphipages.com" name="dynamicframe" scrolling="yes" noresize frameborder="yes">       
      <frameset cols="51%,49%" frameborder="no" border="1" framespacing="0" marginwidth=0 marginheight=0>
        <frame name="mainFrame" scrolling="NO" noresize>
        <frame name="topFrame" scrolling="NO" noresize frameborder="no" border="0">
       
      </frameset>
    <frame name="topFrames" scrolling="NO" noresize frameborder="no">          
  </frameset>
</html>

Save as test.html to C:\
Then set webbrowser1 to navigate to C:\txt.html

Then try this
  showmessage(IntToStr(WebBrowser1.OleObject.Document.frames.Length));
  for f := 0 to WebBrowser1.OleObject.Document.frames.Length - 1 do
    showmessage(intToStr(WebBrowser1.OleObject.Document.frames.item(f).document.Forms.Length));

It came up with 4 as expected, but then got access denied..

 

by: EddieShipmanPosted on 2004-11-29 at 13:25:55ID: 12700449

You can't just navigate to c:\txt.html. You must place it in inetpub\wwwroot and use http://locahost/txt.html.
I tried it that way and got the same result.

 

by: wildzeroPosted on 2004-11-29 at 13:29:45ID: 12700484

Eh?
I placed it on c:\ and naviagated to it just fine
Got the same result as if it was on the internet anyway

 

by: AqueathPosted on 2004-11-29 at 14:07:40ID: 12700764

Hi Guys,

It seems you might be right Eddie about the cross-domain security. I tried the html you posted, and I ran into trouble accessing the objects on delphipages or any other page for that matter, when running a html form locally. I had only tried this previously on pages located on the same domain, as the code below will show. I have NO idea of what is said on the testpage used as my linguistic skills are rather limited, and does not include cyrillic characters in any form ;-) The testpage does however include both frames and a form, and I included a source that works for me on the selected testpage, and demonstrates the basics. Unfortunately it may not work on all pages due to the fact Eddie previously pointed out. Anyway....

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure WebBrowser1DocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Enabled:=False;
  Button2.Enabled:=False;
  Button3.Enabled:=False;
  Button4.Enabled:=False;
  WebBrowser1.Navigate('http://relay.adm.yrg.kuzbass.net/gai/homegai.html');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  showmessage(WebBrowser1.OleObject.Document.frames.length);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  showmessage(WebBrowser1.OleObject.Document.frames.item(1).Document.forms.length);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  WebBrowser1.OleObject.Document.frames.item(1).document.forms.Item(0).Item(0).Value:='Bob';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  WebBrowser1.OleObject.Document.frames.item(1).Document.forms.item(0).submit;
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
  Button1.Enabled:=True;
  Button2.Enabled:=True;
  Button3.Enabled:=True;
  Button4.Enabled:=True;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  WebBrowser1.OleObject.Document.frames.item(1).Document.forms.item(0).submit;
end;

end.


A.

 

by: wildzeroPosted on 2004-11-29 at 14:11:18ID: 12700786

Aqueath - Thanks for the msg and summary, but it doesn't really get me any further ahead then my post "Figured it out! Finally....." I do appreaciate the time you've put into it though... Just gota figure out the cross domain thing...

 

by: EddieShipmanPosted on 2004-11-29 at 14:21:47ID: 12700885

I was working on a MHTML (web archive)  processor and was having major problems with Frames
and IFrames. Then I ran accross a post on comp.infosystems.authoring.html about the cross-domain
security issue.

Now, I am not using IHTMLDocument2 anymore, I just use idHTTP and TRegEx to parse the HTML. When
I run across a frame/iframe, I download the source separately.

I am trying to recreate the technique used in this VB.Net article in Delphi:
http://www.codeproject.com/vb/net/MhtBuilder.asp#xx979211xx

 

by: wildzeroPosted on 2004-11-29 at 14:27:46ID: 12700948

mmmm
thats what I may have to do
A friend pointed out that Robo form handles frames and iframes so there must be some way - maybe it has it's own build in html engine. Who knows. Tis a shame...

 

by: EddieShipmanPosted on 2004-11-29 at 15:08:11ID: 12701273

So, is that what you are doing, building a tool to download entire websites either into a MHT file or a directory?

 

by: wildzeroPosted on 2004-11-29 at 18:24:26ID: 12702304

Negative,

Trying to get the form elements from frames.
I may have to parse the html and if there are frames load them up somehow and go from there...

Herm...

 

by: EddieShipmanPosted on 2004-11-30 at 06:30:21ID: 12706049

but WHY?

 

by: wildzeroPosted on 2004-11-30 at 16:32:25ID: 12711783

So I can fill them out

 

by: EddieShipmanPosted on 2004-12-01 at 06:17:08ID: 12715835

ANy particular site you are working with or just in general?

 

by: wildzeroPosted on 2004-12-01 at 12:06:30ID: 12719889

Just in general, I've got everything working but the cross-domain thing....
:)

 

by: EddieShipmanPosted on 2004-12-01 at 12:19:40ID: 12720012

Well I guess you're out of luck because MS declared that it was unsafe. I don't know if you'd be able to do it
with the Firefox DOM, either.

 

by: wildzeroPosted on 2005-01-24 at 15:24:21ID: 13127025

Thanks everyone for there feedback...

 

by: wildzeroPosted on 2005-01-24 at 15:26:14ID: 13127033

Crap was ment to hit A!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...