Je reprend ce fil ici car ça peut vous intéresser.

Le code ci-dessous montre comment charger un SWF depuis un TStream (resource, file, memory...)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 
unit Main;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;
 
type
  TForm1 = class(TForm)
    OpenDialog1: TOpenDialog;
    procedure FormCreate(Sender: TObject);
  private
    { Déclarations privées }
    procedure LoadSWF(const AFileName: string);
  public
    { Déclarations publiques }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
uses
  ShockwaveFlashObjects_TLB, ActiveX;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  if OpenDialog1.Execute then
    LoadSWF(OpenDialog1.FileName);
end;
 
procedure TForm1.LoadSWF(const AFileName: string);
var
  SWF       : TShockWaveFlash;
  FileStream: TFileStream;
  MemStream : TMemoryStream;
  Len       : Integer;
  Ptr       : ^Integer;
  PStream   : IPersistStreamInit;
  AStream   : IStream;
begin
// Creation de l'ActiveX
  SWF := TShockWaveFlash.Create(Self);
  SWF.Parent := Self;
  SWF.SetBounds(0, 0, ClientWidth, ClientHeight);
 
// Ouverture du fichier, mais ça pourrait être une ressource
  FileStream := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyNone);
  try
  // on va le copier en mémoire
    MemStream := TMemoryStream.Create;
    try
      Len := FileStream.Size;
    // il nous faut 8 octets de plus...
      MemStream.SetSize(Len + 8);
      Ptr := MemStream.Memory;
   // 4 pour stocker la valeur "magique"
      Ptr^ := $55665566; // Magic tag !
      Inc(Ptr);
   // 4 pour stocker la taille du fichier
      Ptr^ := Len;
      Inc(Ptr);
   // et on place le fichier à la suite
      FileStream.ReadBuffer(Ptr^, Len);
 
    // maintenant on demande un PersistStream à l'ActiveX
      IUnknown(SWF.OleObject).QueryInterface(IPersistStreamInit, PStream);
    // on créer un wrapper pour notre stream (pas la peine de le libérer c'est un TInterfacedObject)
      AStream := TStreamAdapter.Create(MemStream);
    // et on le charge, c'est tout !
      PStream.Load(AStream);
 
    finally
      MemStream.Free;
    end;
  finally
    FileStream.Free;
  end;
end;
 
end.