String型的问题!
uses中加入:
ShareMem

解决方案 »

  1.   

    //将string换成PChar或者ShortString
    function  Add(x,y:ShortString):ShortString;stdcall;
    begin
      Result:=x + y;
    end;
      

  2.   

    To:zswang(伴水)(* 嘻 *)    运行没问题了,但是关闭时提示:无效的指示操作。
      

  3.   

    怎么关闭的,使用了函数吗,将dll释放了吗?
      

  4.   

    To:zswang(伴水)(* 嘻 *) unit Test;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TTestfrm = class(TForm)
        lbledtSs: TLabeledEdit;
        lbledtRs: TLabeledEdit;
        lbledtP1: TLabeledEdit;
        lbledtP3: TLabeledEdit;
        lbledtP2: TLabeledEdit;
        lbledtP4: TLabeledEdit;
        btnRev: TButton;
        btnAdd: TButton;
        lbledtRr: TLabeledEdit;
        procedure btnAddClick(Sender: TObject);  private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Testfrm: TTestfrm;
      function  Add(x,y:ShortString):ShortString;stdcall;external '.\Xy.Dll';
    implementation{$R *.dfm}谢谢!
      

  5.   

    //声明要保持一致
    function Add(x,y: ShortString): ShortString; stdcall; external 'Xy.dll';
      

  6.   

    Result:=x + y;会不会返回的值超过ShortString呢?
    建议改用PChar
      

  7.   

    我也遇到过同样的问题,解决方法有两种:
    1 用Pchar代替String:
      将function  Add(x,y:String):String;stdcall;改为
      function  Add(x,y:Pchar):Pchar;stdcall;2 在DLL和主程序的工程文件中引用ShareMem:
     注意:一定要将ShareMem放在USES的首位,否则关闭程序时也会出错!
      

  8.   

    To:zswang(伴水)(* 嘻 *) library Xy;uses
      SysUtils,
      Classes,
      ShareMem;{$R *.res}
    function  Add(x,y:ShortString):ShortString;stdcall;
    begin
      Result:=x + y;
    end;exports
      Add;
    begin  
    end.
    unit Test;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, sharemem;type
      TTestfrm = class(TForm)
        lbledtSs: TLabeledEdit;
        lbledtRs: TLabeledEdit;
        lbledtP1: TLabeledEdit;
        lbledtP3: TLabeledEdit;
        lbledtP2: TLabeledEdit;
        lbledtP4: TLabeledEdit;
        btnAdd: TButton;
        lbledtRr: TLabeledEdit;
        procedure btnAddClick(Sender: TObject);  private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Testfrm: TTestfrm;
      function  Add(x,y:ShortString):ShortString;stdcall;external '.\Xy.Dll';
    implementation{$R *.dfm}
    procedure TTestfrm.btnAddClick(Sender: TObject);
    begin
      lbledtSs.Text:=Add('dasdsad','dsadsadr');
    end;end.
      

  9.   

    你在调用DLL的单元中应用了DLL单元了吗
    Uses
      Xy
      

  10.   

    uses
      SysUtils,
      Classes{,
      ShareMem}; //不要uses ShareMem就正常了
      

  11.   

    我现在遇到的问题和zhuig () 一样,望大家帮忙!!!!