Solved

Reading and writing variants.

Posted on 1998-05-11
2
223 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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