00 Votes

Delphi/Lazarus: Convert Variant-Value to String

Question by Guest | 2015-01-06 at 07:24

I have a variable of the type variant, but in my application, I need a string variable.

Does someone know a way of how to change a variant value into a string? Is that possible somehow?

ReplyPositiveNegative
1Best Answer3 Votes

There is the function VarToStr() for this purpose. You can pass an arbitrary variant value to this function and the function tries to make a string out of it.

var
  v: variant;
  s: string;
begin
  v := 'abc';
  s := VarToStr(v);

  v := 1;
  s := VarToStr(v);
end;

As the example shows, you can also use the function with variant variables that has not been a string type before.
2015-01-06 at 15:12

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.