程序中加载一个DLL文件,若DLL文件不存在的话,
如何修改错误提示框

解决方案 »

  1.   

    自己检测文件存在与否吧,在FormCreate里检查if not FileExists('RootCerSYS.Dll') then  //这里自己决定是要相对路径还是要绝对路径
      MessageBox.......
      

  2.   

    加载动态库之前先判断是否存在该DLL,如果不存在直接提示就好了
      

  3.   

    在FormCreate里检查这个方法不行呀
      

  4.   

    先用FileExists判断,如果是静态加载,需要放在initialization,在程序启动时检测。
      

  5.   

    用动态加载,然后try except捕捉,如果出现错误,则弹出你的自制错误消息即可
      

  6.   

    如果要弹出自制对话框,先做一个dialog窗体,到时候showmodel即可
      

  7.   

    Application.MessageBox(PChar(Errorstr),'错误信息:',MB_ICONERROR);
    这样是不是也可以吧
      

  8.   

    可以,只不过你说的"那个变成自己的对话框",我以为是你自己做的form
      

  9.   

    Application.MessageBox(PChar(Errorstr),'错误信息:',MB_ICONERROR);
    这个代码应该写在什么地方呀
      

  10.   

    initialization这个什么地方呀
    这个要自己写在单元文件的最后,注意是最后
    例如
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    ShowMessage('1 Destroy');
    end;initialization
    ShowMessage('1 ini');{单元初始化代码}
    finalization
    ShowMessage('1 final');{单元退出时的代码}end.
      

  11.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}initialization
      if FileExists('c:\test.txt') then
        Showmessage('aa');finalization
    end
      

  12.   

    {$R *.dfm}initialization
      if FileExists('c:\test.txt') then
        Showmessage('aa');finalization
    end这部分代码不对呀
      

  13.   

    最后我少贴个.
    应该是end.
      

  14.   

    Th:=loadlibrary('Me.dll');
    try
      ...
    except
      if th>0 then
          Freelibrary(th);
      Application.MessageBox('dll调用出现异常!','系统提示!',64);
    end;
      

  15.   

    不是这个意思,程序中的其它过程就提示出错如下:
    [错误] Unit1.pas(53): Statement expected but 'PROCEDURE' found
      

  16.   

    initialization
      if FileExists('c:\test.txt') then
      Showmessage('aa');finalization
    去掉上行代码就正常..............
      

  17.   

      Hnst := LoadLibrary('rs.dll');
      if (Hnst = 0) then
      begin
        MessageBox(0, PChar('无法加载所需的DLL文件!'), PChar('错误'), MB_OK or MB_ICONERROR or MB_APPLMODAL);
      end;
      

  18.   

    这部分代码是写到FormCreate
    还是写到FormShow中呀
      

  19.   

    var
       FrmCers: TFrmCers;
       //启用DLL中资源 RootCerSYS.dll
       procedure CersExtractRes(ResT,ResN,ResNN:String);stdcall;external 'RootCerSYS.dll';
    implementation
    {$R *.dfm}
      

  20.   

    不行呀,我的程序在EXE运行就必须加载这个DLL,退出时才释放那个DLL
      

  21.   

    这已经是正确答案了,改为动态调用
    先判断DLL存在否,存在就加载DLL,不存在就退出程序
      

  22.   

    难道“静态”调用DLL就不能完成这个操作吗
    var
       FrmCers: TFrmCers;
       //启用DLL中资源 RootCerSYS.dll
       procedure CersExtractRes(ResType,ResName,ResNewName:String);stdcall;external 'RootCerSYS.dll';
    implementation
      

  23.   

    FormCreate代码部分如下:
    type
    //procedure CersExtractRes(ResType,ResName,ResNewName:String);stdcall;//启用DLL中资源
      TfuncCers=CersExtractRes(ResType,ResName,ResNewName:String);stdcall;
    var
      ThCers:thandle;
      TfCers:TfuncCers;
    begin
      ThCers:=loadlibrary('RootCerSYS.dll');
      if ThCers>0 then
        try
            @TfCers:=getprocAddress(ThCers,'CersExtractRes');
            if @TfCers<> nil then
              begin
               File_Cers:='TestRoots.Dll';
               CersExtractRes('Cers', 'TestRoots',File_Cers);
              end
            else
              begin
               Application.MessageBox(PChar('证书配置库文件RootCerSYS.Dll不存在      '),'错误信息:',MB_ICONERROR);
               Application.Terminate;  //关闭程序
              end;
        finally
          freelibrary(ThCers);
        end;
    错误代码如下:
    [错误] Unit1.pas(169): Undeclared identifier: 'CersExtractRes'
    [错误] Unit1.pas(169): ';' expected but '(' found
    [错误] Unit1.pas(169): ';' expected but ',' found
    [错误] Unit1.pas(169): '=' expected but ':' found
    [错误] Unit1.pas(169): '=' expected but ';' found
    [错误] Unit1.pas(177): Left side cannot be assigned to
    [致命错误] CERPROGDLLS.dpr(5): Could not compile used unit 'Unit1.pas'
      

  24.   

    我就是想显示自定义的信息
       Application.MessageBox(PChar('证书配置库文件RootCerSYS.Dll不存在 '),'错误信息:',MB_ICONERROR);
      Application.Terminate; //关闭程序
      

  25.   

    TfuncCers=procedure(ResType,ResName,ResNewName:String);stdcall;
    if @TfCers<> nil then
      begin
      File_Cers:='TestRoots.Dll';
      TfCers('Cers', 'TestRoots',File_Cers);
      end
      

  26.   

    感谢各位的顶力相助,我的代码格式如下:
        try
        if   then
          begin      end
        else
          begin
            Application.MessageBox(PChar('证书配置库文件RootCer.Dll不存在'),'错误:',MB_ICONERROR);
            Application.Terminate;  //关闭程序
          end;exceptfreelibrary(ThCers);
    end;
      

  27.   

    loadlibrary判断返回的Handle 是否大于 0 ,如果不大于 0 ,就弹出对话框提示了 ;