Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Saving a variant type with a stream

Posted on 2000-04-14
3
821 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
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:

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
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...
0
 
LVL 1

Author Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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