Solved

Reading and writing variants.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

23 Experts available now in Live!

Get 1:1 Help Now