Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to write a buffer to a TStream ?

Posted on 2003-11-01
2
Medium Priority
?
349 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 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