如何为来自 TStream 的 Olevariant 变量赋值?

发布于 2024-10-03 08:13:13 字数 619 浏览 0 评论 0原文

我需要从 Stream 中读取数据并将读取的缓冲区放入 OleVariant (VarArray) 变量中。

var
MemoryStream : TMemoryStream;
Data : OleVariant;
begin
            MemoryStream:=TMemoryStream.Create;
            try
                FuncFill(MemoryStream); //Filling the stream
                MemoryStream.Seek(0,0);
                MemoryStream.Read(Data, MemoryStream.Size);//this line lock the app, I need allocate the memory for the OleVariant variable?
            finally
             MemoryStream.Free;
            end;

end;

如何将 TMemoryStream 中的读取值分配给 olevariant 变量?

我正在使用德尔福5。

I need to read from a Stream and put the buffer that was read in a OleVariant (VarArray) variable.

var
MemoryStream : TMemoryStream;
Data : OleVariant;
begin
            MemoryStream:=TMemoryStream.Create;
            try
                FuncFill(MemoryStream); //Filling the stream
                MemoryStream.Seek(0,0);
                MemoryStream.Read(Data, MemoryStream.Size);//this line lock the app, I need allocate the memory for the OleVariant variable?
            finally
             MemoryStream.Free;
            end;

end;

How I can assign the read value from the TMemoryStream to a olevariant variable?

I'm using delphi 5.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花辞树 2024-10-10 08:13:13

您可以使用 VarArrayLock 函数获取指针到 OleVariant 数据,然后读取到该指针。

检查此代码,它使用 varByte 元素的 VarArray

var
 MemoryStream : TMemoryStream;
 Data : OleVariant;
 DataPtr : Pointer;
begin
   MemoryStream:=TMemoryStream.Create;
     try
      FuncFill(MemoryStream); //Filling the stream
      MemoryStream.Seek(0,0);
          Data    :=VarArrayCreate([0, MemoryStream.Size - 1], varByte);
      DataPtr     :=VarArrayLock(Data);
       try
         MemoryStream.ReadBuffer(DataPtr^,MemoryStream.Size); //Get the pointer to the variant variable.
       finally
         VarArrayUnlock(Data); //when you are done , you must call to VarArrayUnlock
       end;
    finally
      MemoryStream.Free;
    end;    
end;

You can use the VarArrayLock function to get a pointer to the OleVariant data and then read to this pointer.

check this code wich use a VarArray of varByte elements.

var
 MemoryStream : TMemoryStream;
 Data : OleVariant;
 DataPtr : Pointer;
begin
   MemoryStream:=TMemoryStream.Create;
     try
      FuncFill(MemoryStream); //Filling the stream
      MemoryStream.Seek(0,0);
          Data    :=VarArrayCreate([0, MemoryStream.Size - 1], varByte);
      DataPtr     :=VarArrayLock(Data);
       try
         MemoryStream.ReadBuffer(DataPtr^,MemoryStream.Size); //Get the pointer to the variant variable.
       finally
         VarArrayUnlock(Data); //when you are done , you must call to VarArrayUnlock
       end;
    finally
      MemoryStream.Free;
    end;    
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文