Solved

Reading and writing variants.

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

15 Experts available now in Live!

Get 1:1 Help Now