Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Saving a variant type with a stream

Posted on 2000-04-14
3
Medium Priority
?
839 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
[X]
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
3 Comments
 
LVL 10

Accepted Solution

by:
Lischke earned 400 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
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 response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

705 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