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.
请大哥大姐们帮忙看看错在哪里!
实验代码如下:
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.
请大哥大姐们帮忙看看错在哪里!