delphi onnewfile event

Author Message
Philippe 12/16/2011 12:50 pm
Hi

the onnewfile event is not called when I run the included delphi demo (I replaced the OE:=CreateOleObject('OE.MainOE'); with a OE:TmainOE component;)

What am I missing here?

ps: and are there other events? (to allow to change the filename for example before saving to hardisk?

thanks
regards
philippe
Oleg Chernavin 12/16/2011 01:15 pm
Can you see, if the following code works:

public
OE: TMainOE;
procedure NewURL(Sender: TObject; IID: Integer; var NewURL: OleVariant);
end;


...
procedure TForm1.NewURL(Sender: TObject; IID: Integer; var NewURL: OleVariant);
begin
LB.Items.Add(IntToStr(IID));
LB.Items.Add(NewURL);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
OE := TMainOE.Create(Self);
OE.Connect;
OE.OnProjectURLMoved := NewURL;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
OE.Free;
end;

Best regards,
Oleg Chernavin
MP Staff
Philippe 12/17/2011 04:18 am
Hi Oleg,

thanks for your quick reply. It does not compile :(... : [DCC Error] Unit1.pas(154): E2009 Incompatible types: 'Parameter lists differ'. Now, if I change :
procedure NewURL(Sender: TObject; IID: Integer; var NewURL: OleVariant);
to
procedure NewUrl(ASender: TObject; IID: Integer;const NewURL: WideString);

then it compiles but is never called....

PS: I noted that in the doc, the declaration is NOT the same? OnNewFile(ProjectIID: Integer; URL: String; Filename: String; MIME: String; Referer: String; AbsLevel: Integer);

I have two other questions please:
- Is it possible to have an event that will allow me to tell OE what filename to use for saving a downloaded file (the event would receive url and filename).
- Is it possible to have an event that will allow me to modify the CONTENT of a downloaded html page *before* it is saved? (to remove some sections or fix some problems such as the charset for example) - the event would receive the header and content).

thank you !
regards
philippe



Philippe 12/19/2011 06:29 pm
Oleg

To be complete, Here is the full code with the component initialized in formcreate as you suggested:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComObj, ExtCtrls, ComCtrls,variants, OleServer, OELib_TLB, OE_TLB;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
List: TListBox;
Timer1: TTimer;
Tree: TTreeView;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
btnStop: TButton;
btnStart: TButton;
MainOE1: TMainOE;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Updatelist(Sender: TObject);
procedure TreeChange(Sender: TObject; Node: TTreeNode);
procedure btnStopClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnStartClick(Sender: TObject);
private
{ Private declarations }
public
OE1: TMainOE;

procedure NewURL(ASender: TObject; IID: Integer; const URL,Filename, MIME, Referer: WideString; AbsLevel: Integer);

end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
I : Integer;
J : Integer;
Cnt: Integer;
N : TTreeNode;
V : Variant;
V1 : Variant;
begin
Caption := 'OE Automation sample: ' + OE1.Version;
Cnt := OE1.FoldersCount;
For I := 0 to Cnt - 1 do
begin
V := OE1.GetFolder(I);
if not VarIsEmpty(V) then
begin
N := Tree.Items.Add(nil, V.Caption);
For J := 0 to V.ItemsCount - 1 do
begin
V1 := V.GetItem(J);
if V1.IType = 0 then //Project
Tree.Items.AddChildObject(N, V1.Caption, Pointer(Integer(V1.IID)))
else
Tree.Items.AddChild(N, V1.Caption);
end;
end;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
//OE.Persistent := Integer(101);
end;

procedure TForm1.btnStartClick(Sender: TObject);
var
V: Variant;
begin
if Tree.Selected = nil then
Exit;
if Tree.Selected.Data <> nil then
begin
V := OE1.GetProjectByIID(Integer(Tree.Selected.Data));
if not VarIsEmpty(V) then
V.Start;
end;
end;

procedure TForm1.Updatelist(Sender: TObject);
var
V: Variant;
I: Integer;
J: Integer;
begin
// if VarIsEmpty(OE1) then
// Exit;
I := OE1.ConnectionsCount;
if I < 0 then
Exit;
For J := 0 to I - 1 do
begin
V := OE1.Connection(J);
if not VarIsEmpty(V) then
begin
if List.Items.Count > J then
List.Items[J] := 'HTTP' + IntToStr(J) + ': ' + V.MessageText
else
List.Items.Add('HTTP' + IntToStr(J) + ': ' + V.MessageText);
end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
OE1 := TMainOE.Create(Self);
OE1.ConnectKind:=ckRunningOrNew;
OE1.OnNewfile := NewURL; /// EVENT TO CALL
OE1.Connect;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
OE1.Free;

end;

procedure TForm1.NewURL(ASender: TObject; IID: Integer; const URL,
Filename, MIME, Referer: WideString; AbsLevel: Integer);
begin

showmessage('-------------------------------EVENT NOT CALLED ----------------');
end;

procedure TForm1.TreeChange(Sender: TObject; Node: TTreeNode);
var
V: Variant;
begin
// btnStart.Enabled := False;
// btnStop.Enabled := False;
if Node = nil then
Exit;
if Node.Data <> nil then
begin
V := OE1.GetProjectByIID(Integer(Node.Data));
if not VarIsEmpty(V) then
begin
Label2.Caption := V.URL;
Label4.Caption := IntToStr(V.Level);
btnStart.Enabled := True;
btnStop.Enabled := True;
end;
end;
end;

procedure TForm1.btnStopClick(Sender: TObject);
var
V: Variant;
begin
if Tree.Selected = nil then
Exit;
if Tree.Selected.Data <> nil then
begin
V := OE1.GetProjectByIID(Integer(Tree.Selected.Data));
if not VarIsEmpty(V) then
V.Stop;
end;
end;

end.
Oleg Chernavin 12/19/2011 06:38 pm
The documentation states it correctly. Here is the part of the OE_TLB.pas file that compiles with Offline Explorer:

IMainOEEvents = dispinterface
['{EB7B9783-51DF-11D5-8C6F-00C0DF030E23}']
procedure OnProjectURLMoved(IID: Integer; const NewURL: WideString); dispid 1;
procedure OnExportComplete(IID: Integer); dispid 2;
procedure OnNewProject(IID: Integer); dispid 3;
procedure OnProjectSettingsChanged(IID: Integer); dispid 4;
procedure OnNewFile(IID: Integer; const URL: WideString; const Filename: WideString;
const MIME: WideString; const Referer: WideString; AbsLevel: Integer); dispid 201;
procedure OnDownloadComplete(IID: Integer); dispid 202;
end;

Oleg.