Solved

How to write a buffer to a TStream ?

Posted on 2003-11-01
2
333 Views
Last Modified: 2010-05-18
Hi!

How can I copy a buffer to a TStream ?

I have the following code and it doesn't work:

var
  Stream : TStream;
begin
  Stream.Size := MaxBufferSize;
  Stream.Position := 0;
  Stream.Write(Buffer, Buffer_Length);
end

where Buffer is a Pchar containing the data and Buffer_Length is the length of Buffer.  MaxBufferSize is the max size of Buffer.

On the other hand,  If I do the following it works fine:
var
  Stream : TStream;
  List : TStringList;
begin
  Stream.Size := 0;
  Stream.Position := 0;
  List := TStringList.Create;
  List.Text := Buffer;
  List.SaveToStream(Stream);
  List.Free;
end;

Can somebody please tell me how exactly should I write the 'Buffer' to the stream ? ... The problem with using a TStringList is that the buffer might contain binary data instead of text.

BTW, the above code is just an example, ... that's the reason why I omited the creation of the stream, etc ..
Thanks a lot
0
Comment
Question by:delphi112497
2 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 125 total points
ID: 9664598

If buffer is a pchar, then it should be

Stream.Write(Buffer^, Buffer_Length);

Regards,
Russell

0
 
LVL 2

Expert Comment

by:Robn
ID: 9671423
writing the buffer using Delphi Strings

procedure WriteBuffer(S: TStream; Text: String);
var
  Size: Integer;
begin
  Size := Length(Text);
  if Size > 0 then begin
    S.Write(PChar(Text)^,Size);
  end;
end;
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now