Me ajudem a ajeitar esse breve cód

Delphi

02/04/2004

Olá pessoal,
tempos atras postei aqui um problema q eu tinha tido com uma parte de meu projeto, mas consegui fazer otra coisa e acabei esquecendo, agora voltou a ser necessário o funcionamento da parte q esta com problemas...

o cód por completo esta abaixo:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, SHDocVw,   ActiveX; 

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
function GetFrame(FrameNo: Integer): IWebbrowser2; 
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.GetFrame(FrameNo: Integer): IWebbrowser2;
var 
  OleContainer: IOleContainer; 
  enum: IEnumUnknown; 
  unk: IUnknown; 
  Fetched: PLongint; 
begin 
  while Webbrowser1.ReadyState <> READYSTATE_COMPLETE do 
    Application.ProcessMessages; 
  if Assigned(Webbrowser1.document) then 
  begin 
    Fetched := nil; 
    OleContainer := Webbrowser1.Document as IOleContainer; 
    OleContainer.EnumObjects(OLECONTF_EMBEDDINGS, Enum); 
    Enum.Skip(FrameNo); 
    Enum.Next(1, Unk, Fetched); 
    Result := Unk as IWebbrowser2; 
  end 
  else 
    Result := nil; 
end; 

// Load sample page 
// Testseite laden 
procedure TForm1.Button1Click(Sender: TObject); 
begin
  Webbrowser1.Navigate(´http://www.warebizprogramming.com/tutorials/html/framesEx1.htm´); 
end; 

// Save all frames in single files 
// Alle Frameseiten in einzelne Dateien speichern 
procedure TForm1.Button2Click(Sender: TObject); 
var
  IpStream: IPersistStreamInit;
  AStream: TMemoryStream;
  iw: IWebbrowser2; 
  i: Integer; 
  sl: TStringList; 
begin 
  for i := 0 to Webbrowser1.OleObject.Document.frames.Length - 1 do
  begin 
    iw := GetFrame(i);
    AStream := TMemoryStream.Create;
    try
      IpStream := iw.document as IPersistStreamInit;
      if Succeeded(IpStream.save(TStreamadapter.Create(AStream), True)) then 
      begin 
        AStream.Seek(0, 0); 
        sl := TStringList.Create; 
        sl.LoadFromStream(AStream); 
        sl.SaveToFile(´c:\frame´ + IntToStr(i) + ´.txt´); 
        //  memo1.Lines.LoadFromStream(AStream); 
        sl.Free; 
      end; 
    except 
    end; 
    AStream.Free; 
  end; 
end; 


end.

Bem, basta colocar ele e mais dois button com funções de clic e um webbrowser.
eu uso Delphi 6, e quando vou colocar o aplicativo pra rodar na hora de clicar no Button2 ele acusa um erro de ´Violação no Acesso ( Interface não suportada)... e sublinha o seguinte do cód:
      IpStream := iw.document as IPersistStreamInit;


Ok, alguem sabe o q ocorre aí? como solucionar?


Obrigado


Lipsil

Lipsil

Curtidas 0
POSTAR