我正在开发一个组件delphi 7
,delphi 2006
组件使用一个.pas
(不是我的)文件,该文件需要一个DLL
文件存在于应用程序目录中。
可以将DLL
文件嵌入到组件中,这样当用户将其放在表单上或在运行时创建它时,DLL
会将其放置在应用程序目录中吗?
目前
1)我告诉用户将DLL
文件放在应用程序目录中。
2)DLL
在 Resources 中添加文件,以便在创建时,我可以将其DLL
放入应用程序目录中?来自delphidabbler_embed_resource。这是我用
{Drop the Resource..!!!}
procedure DropDllToApplicationDirectOry(applicationPath : string);
var
RS: TResourceStream;
begin
// Create resource stream
RS := TResourceStream.CreateFromID(HInstance, 100, RT_RCDATA);
try
// applicationPath : example c:\MyTestProject Lee\
if DirectoryExists(applicationPath) then RS.SaveToFile(applicationPath+'myDllFileWhichIsNeeded.dll')
finally
// Free the stream
RS.Free;
end;
end;
这会将DropDllToApplicationDirectOry
资源从{$RmyDllFileWhichIsNeeded.dll.RES}
and drope 带到该位置,但是
DropDllToApplicationDirectOry
当我将组件放在表单上时如何调用它?
我尝试initialization
了该组件,但没有复制 DLL,所以我得到了错误
编辑
对于当RXControls
我们TRxClock
放弃时钟运行在此表单上时,时钟开始运行(显示当前时间)......所以我尝试了这个
constructor Tmycomponeny.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{add dll}
DropDllToApplicationDirectOry(ExtractFilePath(Application.ExeName));
end;
但这不起作用..
的代码RXControls
constructor TRxClock.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
if not Registered then begin
ClockInit;
Registered := True;
end;
Caption := TimeToStr(Time);
ControlStyle := ControlStyle - [csSetCaption]
{$IFDEF WIN32} - [csReplicatable] {$ENDIF};
BevelInner := bvLowered;
BevelOuter := bvRaised;
FTimer := TRxTimer.Create(Self);
FTimer.Interval := 450; { every second }
FTimer.OnTimer := TimerExpired;
FDotsColor := clTeal;
FShowSeconds := True;
FLeadingZero := True;
GetTime(FDisplayTime);
if FDisplayTime.Hour >= 12 then Dec(FDisplayTime.Hour, 12);
FAlarmWait := True;
FAlarm := EncodeTime(0, 0, 0, 0);
end;