function xx(): string;
type
  xx= function(): string; stdcall;
var
  func: xx;
begin
  Result := '0';
  @func := yy('xx');
  if Assigned(@func) then
  begin
    Result := func();
  end;
end;如上:我想知道每一步代表什么意思,求大神告诉啊。其中的 yy('xx')是接口的初始化函数。delphitype@funfunction()

解决方案 »

  1.   

    function xx(): string; // 定义一个 xx 函数
    type
      xx= function(): string; stdcall;// 定义一个名为xx的函数指针类型
    var
      func: xx; // 声明一个名叫func、类型为xx的函数指针变量
    begin
      Result := '0'; 
      @func := yy('xx');// func函数指针指向yy这个函数 
      if Assigned(@func) then // 如果func成功指向yy这个函数
      begin
        Result := func(); 执行func这个函数指针指向的函数,并返回其返回值
      end;
    end;
      

  2.   

    @func := yy('xx'); 这句解释的貌似有误吧。呵呵~
      

  3.   

    DLL动态调用就是这么弄的
    函数定位 @func := yy('xx'); 
      

  4.   


    定义了函数指针,多数用于动态库的调用场合;如下示例:procedure TFrmFirewatcherDllTest.btnCmdStartTestClick(Sender: TObject);
    type  pStartCmd=function (pbuff:PChar;nLen:Word):integer; stdcall;
    var
      hDll:Cardinal;
      startCmd:pStartCmd;
      arrCmd:array [0..255] of Char;
      nLen:Word;
      i:Integer;
      str:string;
    begin
      btnCmdStartTest.Enabled := False;
      hDll := LoadLibrary('..\SourceDLL\FirewatcherDLL.dll');
      try
        if hDll>32 then
        begin
          @startCmd := GetProcAddress( hDll,'START');
          if Assigned( startCmd ) then
          begin
            nlen :=  startCmd( arrCmd, 256 );
            for i:= 0 to nLen-1 do
            begin
              str := str +' '+ IntToHex( Ord(arrcmd[i]), 2 );
            end;
            Memo1.Lines.Add(IntToStr( Memo1.Lines.Count+1)+ ' 【开机】指令长度:'+inttostr(nLen)+ '; 指令数据:'+quotedstr( trim( str ) )       )
          end;
        end;  finally
        FreeLibrary( hDll );
        btnCmdStartTest.Enabled := True;
      end;
    end;