Ver Mensaje Individual
  #4  
Antiguo 01-10-2017
MaxiDucoli MaxiDucoli is offline
Miembro
 
Registrado: feb 2006
Posts: 134
Reputación: 19
MaxiDucoli Va por buen camino
Logré hacer que me agarre los procedure con cosas que encontré por internet.
El programa corre, pero ahora el problema es que no me pasa por NavegadorDocComplete que es donde tendría que hacer la "magia" el programa.
Les dejo el código de la unit.

Código Delphi [-]
unit GoogleTranslatorTool;

interface
uses
 StdCtrls,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, forms,strutils,IdURI, OleCtrls, SHDocVw,MSHTML;


 // Dummy class to hold event handlers:

    // Event handlers:

Type TWB = class
public
class procedure NavegadorDocComplete(ASender: TObject;const pDisp: IDispatch; var URL: OleVariant);
class procedure NavegadorNavComplete2(ASender: TObject;const pDisp: IDispatch; var URL: OleVariant);
class procedure NavegadorProgChange(ASender: TObject; Progress, ProgressMax: Integer);
//procedure NavegadorNav(const URL : widestring);
end;

procedure ObtenerTraduccion(LangIn,LangOut,SourceText : String; Navegador : TWebBrowser);

Var
  WB : TWB;
  //TMyCustomForm : TForm;
  //Navegador : TWebBrowser;
  el,el1: IHTMLElement;
  inputElement: IHTMLInputElement;
  LangSource,LangTarget,TextoInicial,TextoFinal : String;
  CurDispatch: IDispatch;
  Navegador : TWebBrowser;
CONST URL : string= ('https://translate.google.com.ar/?hl=es#');

implementation
uses gltrans;

class  procedure TWB.NavegadorDocComplete(ASender: TObject;const pDisp: IDispatch; var URL: OleVariant);
begin
application.ProcessMessages;
  if (pDisp = CurDispatch) then
  begin
    CurDispatch := nil; {clear the global variable }
    el1 := (navegador.Document as IHTMLDocument3).getElementById('gt-swap');
    el := (navegador.Document as IHTMLDocument3).getElementById('source');
        //el.onclick;
if (Assigned(el)) AND (Assigned(el1)) then
begin
//if Supports(el, IID_IHTMLInputTextElement, TextElement) then
//el := (navegador.Document as IHTMLDocument3).getElementById('source');

TextoFinal := el.outerText;

end;
  end;
end;
class procedure TWB.NavegadorNavComplete2(ASender: TObject;const pDisp: IDispatch; var URL: OleVariant);
begin
application.ProcessMessages;
   if CurDispatch = nil then
    CurDispatch := pDisp;

end;
class procedure TWB.NavegadorProgChange(ASender: TObject; Progress, ProgressMax: Integer);
begin
application.ProcessMessages;
 if ProgressMax = 0  then
begin
if Assigned(el) then (el1.click);
//memo2.Text := el.outerText;
end;
//Form1.Caption := IntToStr(ProgressMax);

                     {if READYSTATE_COMPLETE = 4 then
begin
el := (navegador.Document as IHTMLDocument3).getElementById('result_box');
if Assigned(el) then
if Supports(el, IID_IHTMLInputElement, inputElement) then
TextoFinal :=  inputElement.value;
end;}
end;

procedure ObtenerTraduccion(LangIn,LangOut,SourceText : String; Navegador : TWebBrowser);
var
WebBrow : TWB;
Begin
WebBrow := TWB.Create;
//Navegador := TWebBrowser.Create(Frmmain);
//navegador.Parent := frmmain;
Navegador.OnDocumentComplete := WebBrow.NavegadorDocComplete;
Navegador.OnNavigateComplete2 := WebBrow.NavegadorNavComplete2;
Navegador.OnProgressChange := WebBrow.NavegadorProgChange;

try
Navegador.Navigate(URL + LangIn + '/' + LangOut + '/' + SourceText);
finally
  if assigned(Navegador) then FreeAndNil(Navegador)

end;
End;




end.
Responder Con Cita