order:=TInstr(PFunc)(txt,Key)?
强制转换函数?恐怕不行!

解决方案 »

  1.   

    你的定义为
    function TInStr(Source:PChar;Check:Char):Integer;
    而你的调用为
    order:=TInstr(PFunc)(txt,Key);不用我说了吧,参数当然不对啊
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        procedure Edit2KeyPress(Sender: TObject; var Key: Char);
      private
        { Private declarations }  public
        { Public declarations }  end;var
      Form1: TForm1;
      function TInStr:Boolean; stdcall; external 'd:\ls\project2.dll'name 'Instr';
    implementation{$R *.DFM}procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
    var
     order:Integer;
     txt:PChar;
     PFunc:TFarProc;
    begin
     if Moudle >32 then
      begin
       Edit2.Text := '';
       txt:=StrAlloc(80);
       txt:=StrPcopy(txt,Edit1.Text);
       order:=TInstr(txt,Key);
        if Order = -1 then
         showmessage('不包含该字符')
        else
         showmessage('位于第:'+IntToStr(Order+1)+'位');
      end;
    end;end.
      

  3.   

    PFunc:=GetProcAddress(Moudle,'TInStr');
      

  4.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        procedure Edit2KeyPress(Sender: TObject; var Key: Char);
      private
        { Private declarations }  public
        { Public declarations }  end;var
      Form1: TForm1;
      TInStr = function (Source:PChar;Check:Char):Integer; stdcall; //这句
    implementation{$R *.DFM}procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
    var
     Order :integer;
     PFunc:TInStr ;//这句
     txt:PChar;
     Moudle:THandle;
    begin
     Moudle := Loadlibrary('d:\ls\project2.dll');
     if Moudle >32 then
      begin
       Edit2.Text := '';
       ◎PFunc:=GetProcAddress(Moudle,'InStr');//这句
       txt:=StrAlloc(80);
       txt:=StrPcopy(txt,Edit1.Text);
       order:=PFunc(txt,Key);
        if Order = -1 then
         showmessage('不包含该字符')
        else
         showmessage('位于第:'+IntToStr(Order+1)+'位');
      end;
    end;end.
    //一定行,给分吧。