# Cannot Close Application

**URL:** https://talk.remobjects.com/t/cannot-close-application/28678
**Category:** Hydra
**Created:** [July 31, 2023, 12:51pm UTC](https://talk.remobjects.com/t/cannot-close-application/28678 "2023-07-31T12:51:28Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jptechon](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@jptechon](https://talk.remobjects.com/u/jptechon)
#### Post date: [July 31, 2023, 12:51pm UTC](https://talk.remobjects.com/t/cannot-close-application/28678/1 "2023-07-31T12:51:28Z")

</div>

Hi,

dephi 10.4.1  
Hydra RemObjects Hydra - 6.6.0.1309  
DA RemObjects Data Abstract for Delphi, Server Edition - 10.0.0.1559

Host is VCL, Plugin: fmxVisual PLugin(only some image and Tpath drawing).

If I dont know load the plugin I can close the applcation.

Once I load the Plugin, when at the main form , I run close: even I release the instance and Unload the dll.

I also cant close and in debug no any error.

please advise how to check the error.

Best Regards,  
Joe Hon

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [July 31, 2023, 5:24pm UTC](https://talk.remobjects.com/t/cannot-close-application/28678/2 "2023-07-31T17:24:19Z")

</div>

Hi,

Can you create a simple testcase that reproduces this issue, pls?  
you can drop it to support@ for keeping privacy.

Can you test [FireMonkey Sample](https://docs.hydra4.com/Samples/FireMonkeySample/) , pls?  
does it work correctly ?

---

<div class="post-metadata">

### Author: ![jptechon](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@jptechon](https://talk.remobjects.com/u/jptechon)
#### Post date: [August 1, 2023, 4:20am UTC](https://talk.remobjects.com/t/cannot-close-application/28678/3 "2023-08-01T04:20:41Z")

</div>

Hi,  
after the source tracing, the problem is on ModuleManager.UnloadModules;.

when calling the unloadModules, it hangs.

This is the ModuleManager.

```auto
object ModuleManager: THYModuleManager
  EnforceSecurity = False
  AutoLoad = False
  ResolveInterfacesToOwner = True
  Left = 152
  Top = 96
end

```

I only load one dll by ModuleManager.LoadModules(‘Plgn.dll’);

This is calling Unload.

```auto
procedure ThostDataModule.ReleaseNow;
begin
      ModuleManager.ReleaseInstance(Instance);
      ModuleManager.UnloadModules;
end;

```

The exactly line problem is on

```auto
procedure THYModuleManager.UnloadModule(aModule: THYBaseModule);
var
  filename: string;
  i, idx: Integer;
  controller: THYVCLModuleController;
  lModule: THYModule;
  l_hostaware: IHYVCLHostAware;
begin
  if aModule = nil then Exit;
  lModule := THYModule(aModule);
  filename := lModule.FileName;
  controller := lModule.ModuleController;

  if Assigned(fOnBeforeUnloadModule) then fOnBeforeUnloadModule(Self, lModule);

  // Adds the references to the factories of this module
  for i := 0 to controller.FactoryCount-1 do begin
    idx := fFactoriesRefs.IndexOf(controller.Factories[i]);
    if (idx>=0) then fFactoriesRefs.Delete(idx);
  end;

  if CanUnload(lModule, true) then begin
    if Supports(lModule.ModuleController, IHYVCLHostAware, l_hostaware) then begin
      l_hostaware.Host := nil;
      l_hostaware := nil;
    end;
    fModules.Remove(aModule);<<< this line hang response.
  end;

  if Assigned(fOnAfterUnloadModule) then fOnAfterUnloadModule(Self, filename);
end;

```

You can see my attached and the attached.

 ![2023-08-01_12h09_47](https://talk.remobjects.com/uploads/default/original/3X/d/e/de64eb58281c2a8eb85df12fab1e00f4bf785223.png)  
 ![2023-08-01_12h12_44](https://talk.remobjects.com/uploads/default/original/3X/1/7/1784029e67eaa87197a41f9f4fe13c8124144292.png)

Please advise how to solve.

Joe

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [August 1, 2023, 7:46am UTC](https://talk.remobjects.com/t/cannot-close-application/28678/4 "2023-08-01T07:46:34Z")

</div>

Hi,

You can’t correctly unload visual FMX plugin because the `External exception 87A` exception is raised in `dxgi.dll` when `fmx.FMX.Forms.FinalizeForms` is called.

Add `{$I Hydra.inc}` to `Hydra.VCL.FireMonkeyModule.pas`:

```auto
unit Hydra.VCL.FireMonkeyModule;

{$I Hydra.inc} //<<<< added
interface

```

close Delphi and call `C:\Program Files (x86)\RemObjects Software\Build\install_HY.cmd` with admin rights.

it should solve issue with closing VCL host when visual FMX plugin is used.

---

<div class="post-metadata">

### Author: ![jptechon](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@jptechon](https://talk.remobjects.com/u/jptechon)
#### Post date: [August 1, 2023, 8:35am UTC](https://talk.remobjects.com/t/cannot-close-application/28678/5 "2023-08-01T08:35:23Z")

</div>

May be I used the BuildPcakages\_D27 to install before.

I need use this to build again. Now is solved . Thanks
