Solved

Saving a variant type with a stream

Posted on 2000-04-14
3
811 Views
Last Modified: 2010-04-04
var
  VarArr: Variant;
  gh:^widestring;
begin
  VarArr:=VarArrayCreate([0,1],varVariant);
  VarArr:=Table2['Alpha;Graphic'];
 
  label1.caption:=inttostr(vartype(VarArr[1]));
 
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]);
0
Comment
Question by:flooder
3 Comments
 
LVL 10

Accepted Solution

by:
Lischke earned 100 total points
Comment Utility
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:

var
  S: WideString;

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

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

var
  Size: Cardinal;

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


Ciao, Mike
0
 

Expert Comment

by:jonnyfive
Comment Utility
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...
0
 
LVL 1

Author Comment

by:flooder
Comment Utility
Thanks for the help.
The other question still runs.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

9 Experts available now in Live!

Get 1:1 Help Now