---
url: >-
  /statelake/scripting-reference/functions-and-procedures/variant-functions/vartowidestr.md
---

# VarToWideStr

**VarToWideStr** converts a **variant** type variable or field **V**, into a **widestring**.

If the **variant** is null (has a vartype of 1), then it will return a blank string.

Whereas a **widestring** variable containing text returns a vartype of 8, a **variant** that contains text returns a vartype of 256, so the two variable types are considered to be different and unique.

Unicode characters are handled with ease in both **widestring** and **variant** data types.

Please also review [TVarType](/statelake/scripting-reference/data-types/enumerations/tvartype) for more information.

This function is more commonly used with **variant** type variables, rather than with fields. However when accessing fields, you can achieve the same thing by using the Field Class object **FieldAsString** property.

Please also review [VarToStr](/statelake/scripting-reference/functions-and-procedures/variant-functions/vartostr) for an alternative function.

**Declaration**: Function VarToWideStr(const V : Variant) : WideString;

An example.

```pascal
procedure OnMapEvent(var Value:Variant);
begin
  Value := VarToWideStr(Field.Value);
end;
```

The function can also be responsible for changing the **VarType** as illustrated in the sample code that follows - from 256 to 8.

```pascal
procedure ScriptEvent (var Value : variant);
var
  aVar, dVar : variant;
  aWVar, cWVar : widestring;
begin
  LogInfo('');

 //aVar = variant type
  aVar := 'Hello there βÆ£€èç';
  LogInfo('Text in a VARIANT variable (V) ........ '+ aVar);
 //Vartype is 256
  LogInfo('Data Type for VARIANT variable with TEXT = '+IntToStr(VarType(aVar)));
  LogInfo('');

 //aWVar = widestring type
  aWVar := 'What is up? βÆ£€èç';
  LogInfo('Text in a WIDESTRING variable (V) ........ '+ aWVar);
 //VarType is 8
  LogInfo('Data Type for WIDESTRING variable with TEXT = '+IntToStr(VarType(aWVar)));
  LogInfo('');

 //cWVar = widestring type
  cWVar := VarToWideStr(aVar);
  LogInfo('Result is ................ ' + cWVar);
 //VarType is 8
  LogInfo('Data Type for converted VAR->WIDESTRING variable with TEXT into WIDESTRING variable = '+IntToStr(VarType(cWVar)));
  LogInfo('');

  dVar := VarToWideStr(aVar);
  LogInfo('Result is ................ ' + dVar);
 //VarType is 8
  LogInfo('Data Type for converted VAR->WIDESTRING variable with TEXT into VARIANT variable = '+IntToStr(VarType(dVar)));
  LogInfo('');

 //fVar = variant type
  fVar := null;
  fWVar := VarToWideStr(fVar);
  LogInfo('Result is ................ *' + fWVar + '*');
 //VarType is 8
  LogInfo('Data Type for Null VARIANT variable converted into WIDESTRING = '+IntToStr(VarType(fWVar)));
  LogInfo('');

 end;
```
