Solved

Saving a variant type with a stream

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

803 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