Solved

Reading and writing variants.

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

810 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