首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >delphi 7,FastMM4无法安装

delphi 7,FastMM4无法安装
EN

Stack Overflow用户
提问于 2012-05-28 12:33:20
回答 2查看 3.2K关注 0票数 0

我正在开发一个使用FastMM4的应用程序,该应用程序来自sourceforge.net。因此,我在开始时就将FastMM4.pas添加到uses子句中。在应用程序中,我需要在batch finalization of unit FastMM4;中运行一个FinalizeMemoryManager;文件,如下所示

代码语言:javascript
复制
  initialization
        RunInitializationCode;

  finalization
        {$ifndef PatchBCBTerminate}
        FinalizeMemoryManager;
        RunTheBatFileAtTheEnd; //my code here..calling a procedure
       {$endif}

 end.

那么我为RunTheBatFileAtTheEnd编写的代码是:

代码语言:javascript
复制
 procedure RunTheBatFileAtTheEnd;
 begin
 //some code here....
  sFilePaTh:=SysUtils.ExtractFilePath(applicaTname)+sFileNameNoextension+'_log.nam';
 ShellExecute(applcatiOnHAndle,'open', pchar(sExeName),pchar(sFilePaTh), nil, SW_SHOWNORMAL) ;
 end;

为此,我需要在SysUtils,shellapi单元的uses子句中使用fastmm4。,但使用它们,这条消息来了

但是,如果我从使用中删除SysUtils,shellapi,它就能工作。我仍然需要安装fastmm4的所有功能,但是对于SysUtils,shellapi,fastmm4还没有安装。

我有自己的一个单元,但它的终结是在fastmm4终结之前执行的。

有人能告诉我怎么解决这个问题吗?

编辑- 1

代码语言:javascript
复制
unit FastMM4;
//...
...
implementation

 uses
   {$ifndef Linux}Windows,{$ifdef FullDebugMode}{$ifdef Delphi4or5}ShlObj,{$else}
  SHFolder,{$endif}{$endif}{$else}Libc,{$endif}FastMM4Messages,SysUtils,shellapi;

我的申请

代码语言:javascript
复制
 program memCheckTest;
   uses
      FastMM4,

编辑-2 :

(在@SertacAkyuz回答之后),我删除了SysUtils并使其正常工作,但我仍然需要运行批处理文件才能通过RunTheBatFileAtTheEnd打开外部应用程序。原因是..i希望外部应用程序只在FastMM4之后运行,就像finalization之外的那样。sExeName是将运行文件sFilePaTh(.nam)的应用程序。有人能告诉我怎么做吗?没有uninstalling FastMM4

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-05-28 13:35:43

FastMM检查默认内存管理器是否在安装自己的内存管理器之前通过调用‘system.pa’中的IsMemoryManagerSet函数来设置。如果设置了默认内存管理器,则拒绝设置自己的内存管理器,并显示问题中显示的消息。

该消息中关于‘Quickmm4.pa’的说明应该是该项目的.dpr文件中的第一个单元,其假设是‘Quickmm4.PAS’本身不被修改。

当您修改‘Quickmm4.pa’的uses子句时,如果包含在uses子句中的任何单元中有一个initialization部分,那么这一段代码必须在“Quickmm4.pa”初始化部分之前运行。如果该代码需要通过RTL分配/分配内存,则设置默认内存管理器。

因此,您必须小心地更改‘requmm4.pa’,以避免在uses子句中包括任何这样的单元,比如‘sysutils.pa’。

下面的示例代码(没有错误检查、文件检查等)演示如何在不分配任何内存的情况下使用记事本启动FastMM的日志文件(只要存在日志文件):

代码语言:javascript
复制
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.
票数 5
EN

Stack Overflow用户

发布于 2012-05-29 08:55:45

我同意Sertac的回答,但如果您坚持使用SysUtils.pas,也想给出一个建议。答案是不要使用它,从它中提取出你需要的东西,并把它放在你自己的副本中。下面是您需要的东西-- ExtractFilePath使用LastDeliminator,它使用StrScan,还有2个常量,所以我将它们复制到这个新单元中,并将其命名为MySysUtils.pas

这也被广泛地用于那些不想编译一堆他们永远不会使用的额外代码的人(但是,您必须绝对确定它在任何单位中都没有使用)。

代码语言:javascript
复制
unit MySysUtils;

interface

const
  PathDelim = '\';
  DriveDelim = ':';

implementation

function StrScan(const Str: PWideChar; Chr: WideChar): PWideChar;
begin
  Result := Str;
  while Result^ <> #0 do begin
    if Result^ = Chr then
      Exit;
    Inc(Result);
  end;
  if Chr <> #0 then
    Result := nil;
end;

function LastDelimiter(const Delimiters, S: string): Integer;
var
  P: PChar;
begin
  Result := Length(S);
  P := PChar(Delimiters);
  while Result > 0 do begin
    if (S[Result] <> #0) and (StrScan(P, S[Result]) <> nil) then
      Exit;
    Dec(Result);
  end;
end;

function ExtractFilePath(const FileName: string): string;
var
  I: Integer;
begin
  I := LastDelimiter(PathDelim + DriveDelim, FileName);
  Result := Copy(FileName, 1, I);
end;

end.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10784743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档