Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 652
  • Last Modified:

How to move data between EWB and Delphi vairable?

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
IT79637
Asked:
IT79637
  • 4
1 Solution
 
gurkalCommented:
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
 
IT79637Author Commented:
Just looked at the code.  WOW!!!   That is really cool!!!  I'll give it a try tomorrow.

Thanks.

0
 
IT79637Author Commented:
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
 
IT79637Author Commented:
Upped points.
0
 
IT79637Author Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now