Pre*_*ias 0 delphi delphi-7 fastmm
我正在使用FastMM4来自sourceforge.net的应用程序.所以我FastMM4.pas在开头就添加了使用条款.在应用程序中,我需要运行一个batch文件后,FinalizeMemoryManager;在finalization中unit FastMM4;像这样的
initialization
RunInitializationCode;
finalization
{$ifndef PatchBCBTerminate}
FinalizeMemoryManager;
RunTheBatFileAtTheEnd; //my code here..calling a procedure
{$endif}
end.
Run Code Online (Sandbox Code Playgroud)
然后我的RunTheBatFileAtTheEnd代码是:
procedure RunTheBatFileAtTheEnd;
begin
//some code here....
sFilePaTh:=SysUtils.ExtractFilePath(applicaTname)+sFileNameNoextension+'_log.nam';
ShellExecute(applcatiOnHAndle,'open', pchar(sExeName),pchar(sFilePaTh), nil, SW_SHOWNORMAL) ;
end;
Run Code Online (Sandbox Code Playgroud)
为此,我需要SysUtils,shellapi在fastmm4单元的uses子句中使用.但使用它们就会出现这个消息

但如果我SysUtils,shellapi从使用中删除它的工作原理.我仍然需要安装fastmm4的所有功能,但是SysUtils,shellapi没有安装fastmm4
我有自己的单位,但最终确定是在fastmm4完成之前执行的.
任何人都可以告诉我如何解决这个问题?
编辑 - 1
unit FastMM4;
//...
...
implementation
uses
{$ifndef Linux}Windows,{$ifdef FullDebugMode}{$ifdef Delphi4or5}ShlObj,{$else}
SHFolder,{$endif}{$endif}{$else}Libc,{$endif}FastMM4Messages,SysUtils,shellapi;
Run Code Online (Sandbox Code Playgroud)
我的应用程序
program memCheckTest;
uses
FastMM4,
Run Code Online (Sandbox Code Playgroud)
编辑-2:
(在@SertacAkyuz回答之后),我删除SysUtils它并且它工作,但我仍然需要运行批处理文件来打开外部应用程序RunTheBatFileAtTheEnd.原因是..我想要一个外部应用程序只在FastMM4之后才能运行finalization.该sExeName是将运行该文件的应用程序sFilePaTh(.nam).任何人都可以告诉你怎么做?没有uninstalling FastMM4.
FastMM通过调用IsMemoryManagerSet'system.pas'中的函数来检查默认内存管理器是否已设置,然后再安装自己的内存管理器.如果设置了默认内存管理器,它将拒绝设置自己的内存管理器并显示问题中显示的消息.
该消息中关于'fastmm4.pas'的指令应该是项目中的第一个单元.dpr文件假设'fastmm4.pas'本身没有被修改.
当您修改'fastmm4.pas'的uses子句时,如果uses子句中包含的任何单元都有一个initialization部分,那么该部分代码必须在'fastmm4.pas'的初始化部分之前运行.如果该代码需要通过RTL分配/收费内存,则设置默认内存管理器.
因此,您必须注意将'fastmm4.pas'更改为不在uses子句中包含任何此类单元,例如'sysutils.pas'.
下面的示例代码(没有错误检查,文件检查等..)显示如何使用记事本启动FastMM的日志文件(如果存在日志文件),而不分配任何内存:
var
CmdLine: array [0..300] of Char; // increase as needed
Len: Integer;
SInfo: TStartupInfo;
PInfo: TProcessInformation;
initialization
... // fastmm code
finalization
{$ifndef PatchBCBTerminate}
FinalizeMemoryManager; // belongs to fastmm
// Our application is named 'Notepad' and the path is defined in AppPaths
CmdLine := 'Notepad "'; // 9 Chars (note the opening quote)
Len := windows.GetModuleFileName(0, PChar(@CmdLine[9]), 260) + 8;
// assumes the executable has an extension.
while CmdLine[Len] <> '.' do
Dec(Len);
CmdLine[Len] := #0;
lstrcat(CmdLine, '_MemoryManager_EventLog.txt"'#0); // note the closing quote
ZeroMemory(@SInfo, SizeOf(SInfo));
SInfo.cb := SizeOf(SInfo);
CreateProcess(nil, CmdLine, nil, nil, False,
NORMAL_PRIORITY_CLASS, nil, nil, sInfo, pInfo);
{$endif}
end.
Run Code Online (Sandbox Code Playgroud)