Delphi 7, add dll to application directory when dropping component

I am developing the aa component in delphi 7 and delphi 2006 , the component uses a .pas file (not mine), for which the DLL must be present in the application directory.

Can I insert a DLL file into the component, so when the user places it on the form or creates it at run time, the DLL will be placed in the application directory?

currently

1) I suggest the user to place the DLL file in the application directory.

2) Add the DLL file to Resources, so that when I create it, can I leave the DLL in the application directory? from delphidabbler_embed_resource . I did it with

  {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; 

this DropDllToApplicationDirectOry take a resource from {$RmyDllFileWhichIsNeeded.dll.RES} and put it in the right place, but

How do I call DropDllToApplicationDirectOry this when I remove the component in the form?

I tried the initialization component, but the DLL is not copied, so I get an error enter image description here

RXControls For RXControls TRxClock , when we drop the clock in this form, the clock starts to run (show the current time) ... so I tried this

  constructor Tmycomponeny.Create(AOwner: TComponent); begin inherited Create(AOwner); {add dll} DropDllToApplicationDirectOry(ExtractFilePath(Application.ExeName)); end; 

But that does not work.

RXControls Code

  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; 

enter image description here

+4
source share
4 answers

This idea will not work at all. You assume that the developer will always add your component to the form. But they could accurately check an existing project outside of version control, and then the DLL will not be created.

In my opinion, you should just document the dependency and let the developer ensure that the dependency is consistent. Suggest that they add a DLL to their version control system so that it is extracted from the application directory.

The developer should be aware of this dependency when it comes to deployment. This should be the responsibility of the developer. Therefore, it’s easier and easier to let the developer manage this full stop.

+6
source

Although David is right that the documentation is probably the only reliable approach, your question is interesting.

It seems that you wrote the code to write the dll to a file so that the problem responds to the event that will be fired when the component is created?

If I did this, I would think that I want to check the creation of the component, that the DLL exists, and if not create it at this stage, if not. Is it possible for you to dynamically load a dll? If you can only use statically linked DLLs, then David's path is really the only reliable way.

+3
source

What you request is technically feasible, but ONLY if the DLL is dynamically loaded at runtime using LoadLibrary() . The "Unable to find component" error is the result of static binding to the DLL at compile time, which makes it impossible to retrieve the DLL at run time (if the static linked DLL does not linger, which uses LoadLibrary() internally).

If and only if the DLL is loaded dynamically / delayed, you can extract it from the resources of your component at runtime before the DLL is used. When calling TResourceStream.CreateFromID() do not use the HInstance global variable, use the FindClassHInstance() function FindClassHInstance() . The HInstance global variable HInstance not point to a component module if the component is used in a project with Runtime Packs enabled, but FindClassHInstance() can find the correct module regardless of how the component is associated with the project.

+2
source

Try placing the dll file in the Contains folder of the package you are creating using the project manager from Delphi.

enter image description here

+2
source

Source: https://habr.com/ru/post/1410825/