[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • 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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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