Saving a variant type with a stream

Posted on 2000-04-14
Last Modified: 2010-04-04
  VarArr: Variant;
My question is I need to save the image data through a variant array i cant use anything else. The problem is the variant array returns a reference to a widestring(that is what the label1 is telling us)how do i manage to assign the reference to a pointer or something so i can get the data to save to a stream. What i want to achieve is something like this but it does not work   gh:=pointer(vararr[1]);
Question by:flooder
LVL 10

Accepted Solution

Lischke earned 100 total points
ID: 2716163
Hi Flooder,

if I understand you correctly then you just want to save the widestring returned by VarArr[1]? Well, this is somewhat easy to do:

  S: WideString;

  S := VarArr[1];
  Stream.WriteBuffer(PWideChar(S)^, 2 * Length(S));

To retrieve it later you can also write the length of the string just before the string itself:

  Size: Cardinal;

  S := VarArr[1];
  Size := Length(S);
  Stream.WriteBuffer(Size, SizeOf(Size));
  Stream.WriteBuffer(PWideChar(S)^, 2 * Size);

Ciao, Mike

Expert Comment

ID: 2716228
Hi flooder...

as I have seen in your other posting, you are looking for something like this:

procedure SaveVariant(AnyVar: Variant; Filename : String);
function LoadVariant(Filename : String): Variant;

And, of course, it should save everything in the variant, including any arrays in it. Well, sounds like an intresting pet project :-] Well, I might have some time this weekend and see if I can do something like that (should be possible :-])...

Cya, Jonny...

Author Comment

ID: 2750486
Thanks for the help.
The other question still runs.

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

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…
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…
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 …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

25 Experts available now in Live!

Get 1:1 Help Now