Unable to detect resource leak in X64 VCL app

delphi package - automated exception handling
q675318
Posts: 16
Joined: Sun Dec 02, 2018 9:29 pm

Re: Unable to detect resource leak in X64 VCL app

Post by q675318 »

my fix code
MainDir is setup root dir

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  MyReg: TRegistry;
begin
  MyReg := TRegistry.Create(KEY_WRITE or KEY_READ or KEY_WOW64_64KEY);
  MyReg.RootKey := HKEY_LOCAL_MACHINE;

  //-------------------------------------------------------
  if MyReg.OpenKey('SOFTWARE\Wow6432Node\madshi\madCollection', True) then
  begin
    MyReg.WriteString('',MainDir2);
    MyReg.WriteBinaryData('key',pbyte(keyMem.Memory)^,keyMem.Size);
  end;
  MyReg.CloseKey;

  if MyReg.OpenKey('SOFTWARE\madshi\madCollection', True) then
  begin
    MyReg.WriteString('',MainDir2);
    MyReg.WriteBinaryData('key',pbyte(keyMem.Memory)^,keyMem.Size);
  end;
  MyReg.CloseKey;

  //-------------------------------------------------------
  if MyReg.OpenKey('SOFTWARE\Wow6432Node\Classes\madExceptBugReport\DefaultIcon', True) then
  begin
    MyReg.WriteString('',MainDir+'madExcept\Tools\madExceptViewer.exe');
  end;
  MyReg.CloseKey;
  if MyReg.OpenKey('SOFTWARE\Classes\madExceptBugReport\DefaultIcon', True) then
  begin
    MyReg.WriteString('',MainDir+'madExcept\Tools\madExceptViewer.exe');
  end;
  MyReg.CloseKey;
  //-------------------------------------------------------
  if MyReg.OpenKey('SOFTWARE\Wow6432Node\Classes\madExceptBugReport\shell\open\command', True) then
  begin
    MyReg.WriteString('','"'+MainDir+'madExcept\Tools\madExceptViewer.exe" "%1"');
  end;
  MyReg.CloseKey;
  if MyReg.OpenKey('SOFTWARE\Classes\madExceptBugReport\shell\open\command', True) then
  begin
    MyReg.WriteString('','"'+MainDir+'madExcept\Tools\madExceptViewer.exe" "%1"');
  end;
  MyReg.CloseKey;
  //-------------------------------------------------------
  if MyReg.OpenKey('SOFTWARE\Wow6432Node\Classes\madExceptPlugin\DefaultIcon', True) then
  begin
    MyReg.WriteString('',MainDir+'madExcept\Tools\madPluginMan.exe');
  end;
  MyReg.CloseKey;
  if MyReg.OpenKey('SOFTWARE\Classes\madExceptPlugin\DefaultIcon', True) then
  begin
    MyReg.WriteString('',MainDir+'madExcept\Tools\madPluginMan.exe');
  end;
  MyReg.CloseKey;
  //-------------------------------------------------------
  if MyReg.OpenKey('SOFTWARE\Wow6432Node\Classes\madExceptPlugin\shell\open\command', True) then
  begin
    MyReg.WriteString('','"'+MainDir+'madExcept\Tools\madPluginMan.exe" "%1"');
  end;
  MyReg.CloseKey;
  if MyReg.OpenKey('SOFTWARE\Classes\madExceptPlugin\shell\open\command', True) then
  begin
    MyReg.WriteString('','"'+MainDir+'madExcept\Tools\madPluginMan.exe" "%1"');
  end;
  MyReg.CloseKey;
  MyReg.Free;
end;
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Unable to detect resource leak in X64 VCL app

Post by madshi »

Thanks for finding the cause of the problem q675318!

The reason it still worked on my PC is that madExcept.pas has a special case for my development PC, where madExcept32/64.dll are compiled to "c:\sources\madshi".

Anyway, should be fixed in this build:

http://madshi.net/madCollectionBeta.exe (installer 2.8.8.2)
spanfkyous
Posts: 13
Joined: Fri Nov 10, 2017 1:29 am

Re: Unable to detect resource leak in X64 VCL app

Post by spanfkyous »

q675318 wrote:my fix code
MainDir is setup root dir

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  MyReg: TRegistry;
begin
  MyReg := TRegistry.Create(KEY_WRITE or KEY_READ or KEY_WOW64_64KEY);
  MyReg.RootKey := HKEY_LOCAL_MACHINE;

  //-------------------------------------------------------
  if MyReg.OpenKey('SOFTWARE\Wow6432Node\madshi\madCollection', True) then
  begin
    MyReg.WriteString('',MainDir2);
    MyReg.WriteBinaryData('key',pbyte(keyMem.Memory)^,keyMem.Size);
  end;
  MyReg.CloseKey;

  if MyReg.OpenKey('SOFTWARE\madshi\madCollection', True) then
  begin
    MyReg.WriteString('',MainDir2);
    MyReg.WriteBinaryData('key',pbyte(keyMem.Memory)^,keyMem.Size);
  end;
  MyReg.CloseKey;

  //-------------------------------------------------------
  if MyReg.OpenKey('SOFTWARE\Wow6432Node\Classes\madExceptBugReport\DefaultIcon', True) then
  begin
    MyReg.WriteString('',MainDir+'madExcept\Tools\madExceptViewer.exe');
  end;
  MyReg.CloseKey;
  if MyReg.OpenKey('SOFTWARE\Classes\madExceptBugReport\DefaultIcon', True) then
  begin
    MyReg.WriteString('',MainDir+'madExcept\Tools\madExceptViewer.exe');
  end;
  MyReg.CloseKey;
  //-------------------------------------------------------
  if MyReg.OpenKey('SOFTWARE\Wow6432Node\Classes\madExceptBugReport\shell\open\command', True) then
  begin
    MyReg.WriteString('','"'+MainDir+'madExcept\Tools\madExceptViewer.exe" "%1"');
  end;
  MyReg.CloseKey;
  if MyReg.OpenKey('SOFTWARE\Classes\madExceptBugReport\shell\open\command', True) then
  begin
    MyReg.WriteString('','"'+MainDir+'madExcept\Tools\madExceptViewer.exe" "%1"');
  end;
  MyReg.CloseKey;
  //-------------------------------------------------------
  if MyReg.OpenKey('SOFTWARE\Wow6432Node\Classes\madExceptPlugin\DefaultIcon', True) then
  begin
    MyReg.WriteString('',MainDir+'madExcept\Tools\madPluginMan.exe');
  end;
  MyReg.CloseKey;
  if MyReg.OpenKey('SOFTWARE\Classes\madExceptPlugin\DefaultIcon', True) then
  begin
    MyReg.WriteString('',MainDir+'madExcept\Tools\madPluginMan.exe');
  end;
  MyReg.CloseKey;
  //-------------------------------------------------------
  if MyReg.OpenKey('SOFTWARE\Wow6432Node\Classes\madExceptPlugin\shell\open\command', True) then
  begin
    MyReg.WriteString('','"'+MainDir+'madExcept\Tools\madPluginMan.exe" "%1"');
  end;
  MyReg.CloseKey;
  if MyReg.OpenKey('SOFTWARE\Classes\madExceptPlugin\shell\open\command', True) then
  begin
    MyReg.WriteString('','"'+MainDir+'madExcept\Tools\madPluginMan.exe" "%1"');
  end;
  MyReg.CloseKey;
  MyReg.Free;
end;

Good Job
Post Reply