Solved

Reading and writing variants.

Posted on 1998-05-11
2
225 Views
Last Modified: 2010-04-06
I'm overriding the define properties method of a number of classes to stream my own classes into a file stream.  I create the TReaderProc and TWriterProc for each property and use Reader.ReadString, ReadInteger etc.  My only problem is that I have some variant properties which I need to store in the stream, and there is no ReadVariant and WriteVariant methods.  How do I read and write variants to and from the stream.  The variants are variant arrays of byte.

Cheers

BigMadDrongo
0
Comment
Question by:BigMadDrongo
[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 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1344204
Hi

You could use a method similar to TStrings, except that you write one byte at a time from the array, instead of one string at a time like TStrings.

The writer would look like this:
  Writer.WriteListBegin;
  for I := 0 to Count - 1 do Writer.WriteChar(Chr(YourArr[I]));
  Writer.WriteListEnd;

The reader would look like this:
  Reader.ReadListBegin;
  while not Reader.EndOfList do begin
    NextCh := Reader.ReadChar;
    // Do something with NextCh, e.g. add NextCh to your array...
  end;
  Reader.ReadListEnd;


You could use TReader.Read and TWriter.Write, but Delphi doesn't recommend this method...

Cheers,
JB
0
 

Author Comment

by:BigMadDrongo
ID: 1344205
Cheers for you help.

BigMadDrongo
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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