//调用程序
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TStrArr = array of Pchar;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
type
  TDllReadCard = function(): TStrArr; stdcall;
var
  DllReadCard: TDllReadCard;
  DLLHandle: THandle;
  sStrArr: TStrArr;
begin
  SetLength(sStrArr, 10);
  DLLHandle := LoadLibrary('Project2.dll');
  if DLLHandle <= 0 then
    raise Exception.Create('加载Project2.dll失败!');
  @DllReadCard := GetProcAddress(DLLHandle, 'FDLL');
  if not (@DllReadCard = nil) then
  begin
    sStrArr := DLLReadCard();
  end;
  edit1.Text := sStrArr[2];
end;
end.
dll程序
library Project2;uses
  SysUtils,
  Classes;
type
  TStrArr = array of Pchar;{$R *.res}function FDLL(): TStrArr; stdcall;
var
  sResult: TStrArr;
begin
  SetLength(sResult, 10);
  sResult[1] := Pchar('是');
  sResult[2] := Pchar('否');
  Result := sResult;
end;exports
  FDLL;
beginend.

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
      TStrArr = array of Pchar;
    var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    type
      TDllReadCard = procedure(var StrAyy: TStrArr); stdcall;
    var
      DllReadCard: TDllReadCard;
      DLLHandle: THandle; 
      sStrArr: TStrArr;
    begin
      DLLHandle := LoadLibrary('Project2.dll');
      if DLLHandle <= 0 then
        raise Exception.Create('加载Project2.dll失败!');
      @DllReadCard := GetProcAddress(DLLHandle, 'FDLL');
      SetLength(sStrArr, 10);
      if not (@DllReadCard = nil) then
      begin
        DLLReadCard(sStrArr);
      end;
      Caption := sStrArr[2];
    end;
    end.
    library Project2;{ Important note about DLL memory management: ShareMem must be the
      first unit in your library's USES clause AND your project's (select
      Project-View Source) USES clause if your DLL exports any procedures or
      functions that pass strings as parameters or function results. This
      applies to all strings passed to and from your DLL--even those that
      are nested in records and classes. ShareMem is the interface unit to
      the BORLNDMM.DLL shared memory manager, which must be deployed along
      with your DLL. To avoid using BORLNDMM.DLL, pass string information
      using PChar or ShortString parameters. }uses
      SysUtils,
      Classes;type
      TStrArr = array of Pchar; {$R *.res} procedure FDLL(var AStrArr: TStrArr); stdcall;
    var 
      sResult: TStrArr;
      n, nlength: Integer;
    begin
      nlength := length(AStrArr);
      for n := 0 to nlength - 1 do
      begin
        if n = 1 then
          AStrArr[n] := Pchar('是');
        if n = 2 then
          AStrArr[n] := Pchar('否');
      end;
    end;exports 
      FDLL; 
    begin end.
      

  2.   

    string与动态数组原理是一样的,需要加ShareMem!
    要不你就用静态数组