?
Solved

How to move data between EWB and Delphi vairable?

Posted on 2010-01-12
5
Medium Priority
?
644 Views
Last Modified: 2013-11-23
Hi,

I'm on a WinXP Pro SP3 box using Delphi 7.

I'm trying to integrate a web browser with a Delphi application in the same executable.

I downloaded and installed the Embedded Web Browser (EWB) component from www.bsalsa.com/product.html.

When I run a web based business application using EWB, is it possible to move data between the EWB HTML text fields and Delphi variables?  If so how is it done?

Thank you.
0
Comment
Question by:IT79637
[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
  • 4
5 Comments
 
LVL 2

Accepted Solution

by:
gurkal earned 2000 total points
ID: 26297378
Add bellow funcs and
call FillForm(WBE,'aFieldName','aValue')
also check http://www.cryer.co.uk/brian/delphi/twebbrowser/read_write_form_elements.htm
//uses MSHTML
function GetFormByNumber(WBE: TEmbeddedWB;formNumber: integer): IHTMLFormElement;
var
  Forms: IHTMLElementCollection;
  document: IHTMLDocument2;
begin
  document := WBE.Document as IHTMLDocument2;
  Forms := document.Forms as IHTMLElementCollection;
  if formNumber < Forms.Length then
    Result := Forms.Item(formNumber, '') as IHTMLFormElement
  else
    Result := nil;
end;

procedure FillForm(WBE: TEmbeddedWB;const fieldName: string; const newValue: string);
var
  field: IHTMLElement;
  inputField: IHTMLInputElement;
  selectField: IHTMLSelectElement;
  textField: IHTMLTextAreaElement;
  theForm: IHTMLFormElement;
begin
  theForm := GetFormByNumber(WBE,0);
  field := theForm.Item(fieldName, '') as IHTMLElement;
  if Assigned(field) then
  begin
    if field.tagName = 'INPUT' then
    begin
      inputField := field as IHTMLInputElement;
      inputField.Value := newValue;
      inputField.Checked := true;
    end
    else
    if field.tagName = 'SELECT' then
    begin
      selectField := field as IHTMLSelectElement;
      selectField.Value := newValue;
    end
    else
    if field.tagName = 'TEXTAREA' then
    begin
      textField := field as IHTMLTextAreaElement;
      textField.Value := newValue;
    end;
  end;
end;

Open in new window

0
 
LVL 1

Author Comment

by:IT79637
ID: 26300210
Just looked at the code.  WOW!!!   That is really cool!!!  I'll give it a try tomorrow.

Thanks.

0
 
LVL 1

Author Comment

by:IT79637
ID: 26509123
Hi,

This is my first attempt to move data between Delphi and TWebBrowser control. I got the code from:

 http://www.cryer.co.uk/brian/delphi/twebbrowser/read_write_form_elements.htm

 I selected the function to list all the fields on a web page.  I copied the function: function GetFormFieldNames(fromForm: IHTMLFormElement): TStringList; to the bottom of the Unit1.pas file.  Additionally I added  MSHTML to my Uses statement.  From the IDE menu, I selected --> Project, Project Options, Directories/Conditionals and added the directory where MSHTML.pas and MSHTML.dcu are located to the "Search Path".

I added my own Button OnClick event and copied the www.cryer.co.uk code directly into my program.  When I compile and run the code I get several errors.

Please see the screen shot below.

What have I neglected to do?

Thanks much.




0
 
LVL 1

Author Comment

by:IT79637
ID: 26509126
Upped points.
0
 
LVL 1

Author Comment

by:IT79637
ID: 26509195
Lost Code and Image when I clicked Rich Test.  Both are available below.
procedure TForm1.btnListFieldsClick(Sender: TObject);
var
  document: IHTMLDocument2;
  theForm: IHTMLFormElement;
  index: integer;
begin
  document := WebBrowser1.Document as IHTMLDocument2;
  theForm := GetFormByNumber(WebBrowser1.Document as IHTMLDocument2,0);
  fields := GetFormFieldNames(theForm);
  for index := 0 to fields.count-1 do
    ShowMessage('Field ' + IntToStr(index) + ' called ' + fields[index]);
end;

function GetFormFieldNames(fromForm: IHTMLFormElement): TStringList;
var
  index: integer;
  field: IHTMLElement;
  input: IHTMLInputElement;
  select: IHTMLSelectElement;
  text: IHTMLTextAreaElement;
begin
  result := TStringList.Create;
  for index := 0 to fromForm.length do
  begin
    field := fromForm.Item(index,'') as IHTMLElement;
    if Assigned(field) then
    begin
      if field.tagName = 'INPUT' then
      begin
        // Input field.
        input := field as IHTMLInputElement;
        result.Add(input.name);
      end
      else if field.tagName = 'SELECT' then
      begin
        // Select field.
        select := field as IHTMLSelectElement;
        result.Add(select.name);
      end
      else if field.tagName = 'TEXTAREA' then
      begin
        // TextArea field.
        text := field as IHTMLTextAreaElement;
        result.Add(text.name);
      end;
    end;
  end;
end;

Open in new window

HTML5.jpg
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

765 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