به این مثال توجه کنید.
نکته 1: این مثال برای تست اینکه ActiveX رجیستر شده یا نه ابتدا سعی میکند یک نمونه از آن را ایجاد کند. اگر عملیات ایجاد با مشکل مواجه شد نشانه آن است که ActiveX قبلا رجیستر نشده است و بنابراین آنرا رجیستر میکند.
نکته 2: برای بوجود آوردن یونیت ShockwaveFlashObjects_TLB و یا هر یونیت Type Library دیگری (TLB) کافی است از منوی کامپوننت ActiveX مورد نظر را Import کنید. فایل TLB مربوطه بطور خودکار ساخته خواهد شد و سپس میتوانید آنرا در برنامه تان Use کنید.
program Project1;
uses
ShockwaveFlashObjects_TLB,
Dialogs,
Windows,
SysUtils,
Classes,
Controls,
Forms,
Unit1 in 'Unit1.pas' {Form1}
{$R *.RES}
{ Function GetWinSysDir() }
function GetWinSysDir: string;
var
n: integer;
p: PChar;
begin
n := MAX_PATH;
p := stralloc(n);
getsystemdirectory(p, n);
Result := Result + strpas(p);
end;
{Function CopyFile() }
procedure Copyfile(InFile, OutFile: string);
var
Inf, Outf: TFileStream;
Over: Boolean;
res: word;
InFFale, OutFFale: boolean;
begin
if FileEXists(InFile) then
begin
if FileExists(OutFile) then
begin
// Res := MessageDlg('Do you want to overwrite existing file?', mtWarning,
// [mbYes, mbNo], 0);
// Over := (Res = mrYes);
Over:=True;
end
else
Over := true;
inffale := false;
outffale := false;
if over then
begin
try
try
InF := TFileStream.Create(Infile, Fmopenread or fmShareDenyNone);
except
on e: Exception do
inffale := true;
end;
try
OutF := TFileStream.create(Outfile, FmCreate or FmShareExclusive);
except
on E: Exception do
outfFale := true
end;
outf.copyfrom(Inf, 0);
finally
if not inffale then
FreeAndNil(Inf);
if not outfFale then
FreeAndNil(outF);
end;
end;
end;
end;
{Function RegisterOCX() }
function RegisterOCX(OcxFilename: string): Boolean;
var
hDll: THandle;
pFunc: function: Integer;
nResult: Integer;
begin
{ This sample implies that the dll is in the PATH }
hDll := LoadLibrary(pchar(OcxFilename));
if hDll = 0 then
MessageDlg('Cannot load library ' + OcxFilename, mtError, [mbOK], 0)
else
begin
pFunc := GetProcAddress(hDll, 'DllRegisterServer');
if not Assigned(pFunc) then
MessageDlg('Library does not export function DllRegisterServer.',
mtError, [mbOK], 0)
else
begin
nResult := pFunc();
if nResult <> 0 then
result := false
else
result := true;
end;
FreeLibrary(hDll);
end;
end;
{ Program Main Body}
var
p: TShockwaveFlash;
begin
try
p := TShockwaveFlash.Create(nil);
except
//ShowMessage('Flash Player Not Installed');
if (FileExists(GetWinSysDir + '\Macromed\Flash\Flash.ocx')) then
begin
RegisterOCX(GetWinSysDir + '\Macromed\Flash\Flash.ocx');
end
else
begin
If Not(FileExists(GetWinSysDir + '\Flash.ocx')) Then
CopyFile(ExtractFilePath(Application.exena me)+'Flash.ocx', GetWinSysDir + '\Flash.ocx');
RegisterOCX(GetWinSysDir + '\Flash.ocx');
end;
end;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.