• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

C++ to Delphi Translation

Hi all,

I found this code but it's in C++ ...can anyone translate this to Delphi please?

Please see code below:

thx

st3vo

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    IHTMLDocument2*   doc;  
    HRESULT   hr   =   CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,(void**)&doc); 

    if(hr   ==   S_OK)  
    {  
          VARIANT   var;  
          VARIANT_BOOL         receive;  
          doc->execCommand(L"InsertImage",t rue,v ar, &receive);  
          doc->Release();  
    }  

}

Open in new window

0
ST3VO
Asked:
ST3VO
  • 3
1 Solution
 
thiagoblimeiraCommented:
Before using this code you must import the typelibrary Microsoft HTML Object Library, and add the MSHTML_tlb.pas to your uses clause and the page you want to insert the image must be loaded;

procedure TForm1.Button1Click(Sender: TObject);
var
doc: IHTMLDocument2;
hr: HRESULT;
vr: VARIANT;
receive: VARIANT_BOOL;
begin
  hr := DelphiWebBrowser1.Document.QueryInterface(IID_IHTMLDocument2,doc);
  if(hr = S_OK) then
    begin
    doc.execCommand('InsertImage',true, receive);    
    doc._Release;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DelphiWebBrowser1.Navigate('www.google.com');
end;
0
 
ST3VOAuthor Commented:
It almost compiles..just 1 error:

[DCC Error] Unit1.pas(847): E2003 Undeclared identifier: 'VARIANT_BOOL'

any ideas?
0
 
ST3VOAuthor Commented:
Tried Boolean and it worked great!

Thanks a lot!!!
0
 
ST3VOAuthor Commented:
Perfect
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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