有关SWF控件的使用(绝对高手请进入)!(100分)

  • 主题发起人 主题发起人 D_LOVER
  • 开始时间 开始时间
D

D_LOVER

Unregistered / Unconfirmed
GUEST, unregistred user!
我想动态从MemoryStream内存流中导入Flash影片内容,而不是为SWF控件指定文件名,
实验代码如下:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs,Activex,Axctrls, ComObj,StdCtrls, OleCtrls, ShockwaveFlashObjects_TLB;

type
TForm1 = class(TForm)
swf: TShockwaveFlash;
btnImport: TButton;
btnFile: TButton;
OpenDialog1: TOpenDialog;
procedure btnImportClick(Sender: TObject);
procedure btnFileClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
stream:TMemoryStream;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.btnImportClick(Sender: TObject);
var
IStr: IStream;
hMem: HGLOBAL;
psi: IPersistStreamInit;
begin
try
try
hMem := GlobalAlloc(GPTR, Stream.Size);
if hMem = 0 then RaiseLastWin32Error;
CopyMemory(Pointer(hMem),stream.Memory,Stream.Size));
OleCheck(CreateStreamOnHGlobal(hMem, True, IStr));
psi:=IUnknown(swf.OleObject) as IPersistStreamInit;
OleCheck(psi.InitNew);
OleCheck(psi.Load(IStr)); <—在这里出错,提示“意外错误”
finally
psi:=nil;
IStr:=nil;
end;
except
ShowMessage('Ole Error!');
end;
end;

procedure TForm1.btnFileClick(Sender: TObject);
var
fileName:string;
begin
if OpenDialog1.Execute then
fileName:=Opendialog1.FileName;
if filename<>'' then
stream.LoadFromFile(filename);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
stream:=TMemoryStream.Create;
end;

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

end.
请大哥大姐们帮忙看看错在哪里!
 
OleCheck(psi.Load(IStr)); 好象是正常的,
根据文档 ,你前面调用了 InitNew,Load 必须返回E_UNEXPECTED
而这个数是负的。所以 OleCheck 会........

showmessage(inttostr(E_UNEXPECTED)+'='+inttostr(psi.Load(IStr)));

IPersistStreamInit::Load
Same as IPersistStream::Load.

HRESULT Load(
LPSTREAM pStm //Pointer to the stream from which the object
//should be loaded
);

Remarks
Notes to Implementers
If the object has already been initialized with InitNew, then this method must return E_UNEXPECTED.
//// //////////
 
我将OleCheck去掉了,虽然不提示错误了,但SWF控件没有任何变化
jsxjd兄,能否帮忙把我的想法实现一下,谢了!
 
哪里有SWF控件下载?能给我一个吗?xiaxifan@vip.sina.com
 
难道这个问题没人知道了吗
 
没有这个必要了
我试过许多次了
最好的方法还是把它用文件流存为临时文件
在movie:=临时文件名
 
后退
顶部