Jump to content
Sign in to follow this  
TurboMagic

DEC: why could this be necessary?

Recommended Posts

While further working on Delphi Encryption Compendium I stumbled over the freeing mechanism for the class registration mechanism.

Digging into the history I read something about AddModuleUnloadProc being used in context of packages, which I didn't use yet,

but I'm not sure why a simple TDECHash.ClassList.Free; should not be sufficient. So any ideas why this is in?

 

I'm asking, because in that ModuleUnload procedure C++ Builder crashes with "List item not found".
So if removing that ModuleUnload completely without causing any negative side effects, it might improve C++ Builder compatibility.

 

nit DECHashBase;

[..]

procedure ModuleUnload(Instance: NativeInt);
var // automaticaly deregistration/releasing
  i: Integer;
begin
  if TDECHash.ClassList <> nil then
  begin
    for i := TDECHash.ClassList.Count - 1 downto 0 do
    begin
      if NativeInt(FindClassHInstance(TClass(TDECHash.ClassList[i]))) = Instance then
        TDECHash.ClassList.Remove(TDECHash.ClassList[i].Identity);
    end;
  end;
end;

initialization
  AddModuleUnloadProc(ModuleUnload);

  TDECHash.ClassList := TDECClassList.Create;

finalization
  RemoveModuleUnloadProc(ModuleUnload);

  TDECHash.ClassList.Free;
end. 

 

Share this post


Link to post
Guest

I don't have a complete answer, but want to make few points,

first : the following is the right way, as the original sequence is definitely wrong

initialization
  TDECHash.ClassList := TDECClassList.Create;
  AddModuleUnloadProc(ModuleUnload);

 

Also i want to suggest to redo the whole thing right, as clearly it had being implemented with some ticking disasters like using NativeInt for HINST !

The way to find by instance then remove from local list by Identity, this makes me uncomfortable, it looks like the code is not clear and this part had been implemented as a workaround, not belongs to the library itself.

 

So redesign it right in clear way, use Delphi and keep it simple and clear, most likely will work just fine for CBuilder without any change.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×