执行程序调用
  Mydll.MyProc(MyStream);DLL中
  procedure myproc(aStream: TStream);
  begin
    aSTREAM.Size := 0;  // 出错
    // 后面我还有对aSTREAM的一些其他操作,很多方法都不是Tstream的virtual方法  end;
我想在DLL使用STREAM,有什么办法解决吗?

解决方案 »

  1.   

    TStream是一个抽象类,换成TMemoryStream
    另外流的大小不时随便赋值的,你写入了多少字节stream.size是自动计算的
    另外如果要定位,使用stream.positon:=0
    最好使用read方法读,write方法写
    例如
              Stream := TMemoryStream.Create;
              TBlobField(qryTmp.FieldByName('c_grd_proText')).SaveToStream(Stream);
              Stream.Position := 0;
              Stream.Read(GridPro.storeInfo, Stream.size);
      

  2.   

    //1:定义一个类型
    type
      PStream = ^TStream;//2:重新定义导出函数量
    procedure myproc(aStream: Pointer);export;
    var
      xx:PStream;
    begin
      xx:=aStream;
      xx^.Size := 0;  // 出错
      // 后面我还有对aSTREAM的一些其他操作,很多方法都不是Tstream的virtual方法end;//3:调用说明
    var
      astream:TStream;
    begin
      astream:=TStream.Create;
      try
        myproc(@astream);
      finally
        astream.Free;
      end;
    end;
      

  3.   

    Mydll.MyProc(MyStream);这个要保证是一个不是TStream创建的变量
      

  4.   

    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;var
      Form1: TForm1;
    procedure TestM(s: TStream); stdcall; external 'ProjDLL.dll';
    implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      ms: TMemoryStream;
      str: string;
    begin
      ms := TMemoryStream.Create;
      TestM(ms);
      SetLength(str, ms.size);
      ms.Position := 0;
      ms.Read(str[1], ms.Size);
      FreeAndNil(ms);
      ShowMessage(str);end;end.---------------------
    library ProjDLL;{ 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;{$R *.res}procedure TestM(s: TStream); stdcall; export;
    var
      str: string;
    begin
      str := FormatDateTime('YYYY-MM-DD HH:NN:SS.zzz', now);
      s.Size := 0;
      s.Write(str[1], length(str));
    end;
    exports TestM ;
    begin
    end.