我在编译DLL的时候,出现下面的提示:
[Warning] Rc_ExcelPart.dpr(215): Return value of function 'Rc_Excel_Check' might be undefined当我注释掉一些代码的时候,再编译就没有这个Warning了。
我注释掉的代码是:
//ExcelApp1, WorkBook1: Variant;    //操作excel的变量
以及引用这俩个变量的代码哪位给个解释呀?

解决方案 »

  1.   

    把Rc_Excel_Check这个function贴出来看看挖!~
      

  2.   

    function 'Rc_Excel_Check' 没有返回值啊比如是 function Rc_Excel_Check: boolean;那你要在里面加入
    result := true; //之类的
      

  3.   

    to aiirii(ari-淘金坑) 
    有返回值的,
    function Rc_Excel_Check(const  ServerName, DataBaseName, sqluserid, sqlpassword,
        DCode, PeriodNo, xlsFileName: PChar): WideString; stdcall;
    我双击那个提示,定位到行:
            Result := '文件名不合法';
      

  4.   

    我双击那个提示,定位到行:
            Result := '文件名不合法';这是这个dll里的第一处result
      

  5.   

    有道理,function是要有返回值的。
      

  6.   

    下面的DLL,出现类似的提示:
    [Warning] calculate.dpr(158): Return value of function 'specialF' might be undefined
    源代码:
    library calculate;uses
      SysUtils,
      Classes;{$R *.res}//定义操作符号
    const
    sopps:string=('+-*/^');
    //var EvaluationError:string;function evaluate(s0:string):extended;forward;//查看括号是否匹配
    procedure matchbracket(var i:integer;s0:string);
       var j,len:integer;
    begin
          j:=1;len:=length(s0);
          repeat inc(i);
                 if i>len then raise EparserError.Create('missing '')''');
                 if s0[i]='(' then inc(j);
                 if s0[i]=')' then dec(j);
                 if j<0 then raise EparserError.Create('missing ''(''');
          until j=0;
    end;function CanMatchBracket(str:string):boolean;
    var i,j,len:integer;
    begin
       result:=false;
       j:=0;
       len:=length(str);
       for i:=0 to len do
       begin
         if str[i]='(' then inc(j);
         if str[i]=')' then dec(j);
       end;
       if j=0 then result:=true;
    end;//把空格和tab,enter清理掉
    procedure cleanup(var s0:string);
    var i:integer;
    begin
         s0:=lowercase(s0);
         //清理空格
         i:=pos(' ',s0);
         while i>0 do
         begin
          delete(s0,i,1);
          i:=pos(' ',s0);
         end;
         //清理TAB
         i:=pos(#10,s0);
         while i>0 do
         begin
          delete(s0,i,1);
          i:=pos(#10,s0);
         end;
         //清理回车
         i:=pos(#13,s0);
         while i>0 do
         begin
          delete(s0,i,1);
          i:=pos(#13,s0);
         end;
    end;//函数相关
    function specialF(p1:integer;s0:string):extended;
    var
      operstr,prestr,laststr,tempstr:string;
      //dmax,dmin,
      arg:extended;
      aa:array of string;
      bb:array of double;
      i,len:integer;
    begin
    arg := 0;
       operstr:=copy(s0,1,p1-1);
       if s0[length(s0)]<>')' then EparserError.CreateFmt('incorrect syntax %s',[s0]);   S0:=copy(s0,p1+1,length(s0)-p1-1);   i:= pos(',',S0);
       if i<>0 then
         begin
             //利用aa[i]来提取参数
           setlength(aa,0);
           while i<>0 do
             begin
               prestr:=copy(s0,0,i-1);
               laststr:=copy(s0,i+1,length(s0));
               if  CanMatchBracket(prestr) and  CanMatchBracket(laststr) then
               begin
                  len:=length(aa);
                  setlength(aa,len+1);
                  aa[len]:=prestr;
                  setlength(bb,len+1);
                  bb[len]:=evaluate(aa[len]);
                  s0:=laststr;
                  i:= pos(',',S0);
                  tempstr:=laststr;
               end else
               begin
                  I:=pos(',',laststr);
                  if i<>0 then i:=i+1+length(prestr) else break;
               end;
          end;
           //最后一个的提取
            len:=length(aa);
            setlength(aa,len+1);
            aa[len]:=tempstr;
            setlength(bb,len+1);
            bb[len]:=evaluate(aa[len]);
          //参数提取完毕,正式计算
          if  operstr ='max' then
          begin
            result:=bb[0];
            for i:=0 to len do
            begin
              if bb[i]>result then result:=bb[i];
            end;
          end;      if  operstr ='min' then
          begin
            result:=bb[0];
            for i:=0 to len do
            begin
              if bb[i]<result then result:=bb[i];
            end;
          end;      if operstr='if' then
          begin
          end;
         end else
         //没有参数情况下的计算
         begin
            if S0<>'' then arg:=evaluate(S0);
                 if operstr ='sin'     then result:=sin(arg)
            else if operstr ='cos'     then result:=cos(arg)
            else if operstr ='tan'     then result:=sin(arg)/cos(arg)
            else if operstr ='arctan' then result:=arctan(arg)
            else if operstr ='log'    then result:=ln(arg)/ln(10)
            else if operstr ='ln'     then result:=ln(arg)
            else if operstr ='exp'    then result:=exp(arg)
            else if operstr ='sqrt'   then result:=sqrt(arg)
            {这里可以添加新的函数}
            {enter additional functions here}
            else raise EparserError.CreateFmt('unknown function %s',[s0]);
         end;
    end; //158行
      

  7.   

    {续}
    //简单的计算
    function Mycalculate(p1:integer;s0:string):extended;
       var v1,v2:extended;
    begin
       v1:=evaluate(copy(s0,1,p1-1));
       v2:=evaluate(copy(s0,p1+1,length(s0)-p1));
       case s0[p1] of
            '+': result:=v1+v2;
            '-': result:=v1-v2;
            '/': result:=v1/v2;
            '*': result:=v1*v2;
            '^': result:=exp(v2*ln(v1));
            else raise EparserError.CreateFmt('invalid operation %s',[s0]);
            end;
    end;//查找第一个操作符号
    function getfirstopp(tot:integer;s0:string):integer;
      var i:integer;
      begin
         if tot=0 then tot:=length(s0);
         //前面的定义sopps='+-*/^'
         for i:=1 to 5 do
             begin
               result:=pos(sopps[i],s0);
               //如果找到+-号
               if ((i<3) and (result>0)) then
                       if ((result=1) or (pos(s0[result-1],sopps)>0)) then result:=0;
               //如果找到,但是在s0的中间,那么退出,返回运算符号
               if result>0 then if result<tot then exit;
             end;
         //如果找到在tot后,则返回0,即错误的返回
         if result>tot then result:=0;
      end;//===============主程序的解析计算==============
    function evaluate(s0:string):extended;
    var
       p1,p2,q1:integer;
    begin
       //如果首行为负号
       if pos('-',s0)=1 then s0:='0'+s0;
       p1:=pos('(',s0);
       p2:=p1;
       //检查括号是否匹配
       if p2>0 then matchbracket(p2,s0);
       //如果第一个就是'('那么把前后的括号去掉,继续计算;
       if p1=1 then begin
                    if p2=length(s0) then begin
                                          delete(s0,p2,1);
                                          delete(s0,1,1);
                                          result:=evaluate(s0);
                                          end
                                     else result:=Mycalculate(p2+1,s0);
                    exit;
                    end;
       //在第一个不是括号情况下的运算=(普通计算+函数符号计算)
       //取得第一个运算符号
       q1:=getfirstopp(p1,s0);
       //p1=0且q1=0,那么最后的计算值显示
       if (p1+q1=0) then begin
                         //result:=getvalue(s0);
                         result:=strtofloat(s0);
                         exit;
                         end;
       //运算符号存在
       if q1<>0 then result:=Mycalculate(q1,s0)
                   //运算符号不存在,但是括号存在
                   else if length(s0)>p2 then result:=Mycalculate(p2+1,s0)
                                         else result:=specialF(p1,s0);
    end;////////////////////////////////
    function getevaluatedString(text: String): WideString; stdcall;
    var
        s0:string;
    begin
        s0:=text;
        TRY
            cleanup(s0);
            result := floattostr(evaluate(s0));
        EXCEPT
            on e:exception do
                result := e.message;
        END;
    end;exports
      getevaluatedString;begin
    end.
      

  8.   

    在你这个函数最开始加上这句就行了。
    result:= 0.0;
      

  9.   

    多谢了,能说明下为什么嘛?我觉得就是加了这句result:= 0.0;,当回返的值是0.0的时候,也不是由这句代码返回的,那为什么还要加呢?难道是编译器的问题?
      

  10.   

    我贴出源代码的DLL是可以了,但是原来说的那个DLL还是有问题[Warning] Rc_ExcelPart.dpr(287): Return value of function 'Rc_Excel_Check' might be undefined
    begin
        Result := '';//287行
    为什么呢?
    同样的问题,只是返回值类型不一样,为什么解决方法不通用呢?
      

  11.   

    其实虽然你的函数有返回值,但是可能存在一种情况,就是有分支、有中断的时候,可能你的result语句就执行不到了,就变成没有返回值了,所以你可以在函数开始就给result赋一个初值