Welcome to %s forums

BrainModular Users Forum

Login Register

Use of 'variant' with getObject

I need help on a Patch
Post Reply
woodslanding
Member
Posts: 1327
Contact:

Use of 'variant' with getObject

Unread post by woodslanding » 27 Nov 2022, 23:57

I've not seen the type 'variant' before. Is there a way to query what type it is?? How do I know whether to treat it as a string or a value?
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 28 Nov 2022, 09:13

the manual is not up to date on this point... sorry
use the function VarType(const V: Variant): TVarType;

Code: Select all

  type TVarType = Word;

  {------------------------------------------------------------
  The variant types are described in the following table: 
  varEmpty  The variant is Unassigned.  
  varNull  The variant is Null.  
  varAny  Represents a Variant that can hold any value.  
  varSmallint  16-bit signed integer (type Smallint in Delphi, short in C++).  
  varInteger  32-bit signed integer (type Integer in Delphi, int in C++).  
  varSingle  Single-precision floating-point value (type Single in Delphi, float in C++).  
  varDouble  Double-precision floating-point value (type double).  
  varCurrency  Currency floating-point value (type Currency).  
  varDate  Date and time value (type TDateTime).  
  varOleStr  Reference to a dynamically allocated UNICODE string.  
  varDispatch  Reference to an Automation object (an IDispatch interface pointer).  
  varError  Operating system error code.  
  varBoolean  16-bit Boolean (type WordBool).  
  varVariant  Indicates another variant.  
  varUnknown  Reference to an unknown object (an IInterface or IUnknown interface pointer).  
  varShortInt  8-bit signed integer (type ShortInt in Delphi or signed char in C++).  
  varByte  A Byte.  
  varWord  Unsigned 16-bit value (Word).  
  varLongWord  Unsigned 32-bit value (type LongWord in Delphi or unsigned long in C++).  
  varInt64  64-bit signed integer (Int64 in Delphi or __int64 in C++).  
  varStrArg  COM-compatible string.  
  varString  Reference to a dynamically allocated string (not COM-compatible).  
  varArray  Indicates a Variant array.  
  varByRef  Indicates that the variant contains a reference as opposed to a value.  
  varTypeMask  Indicates the type of each array element. 
  -----------------------------------------------------------------}

  type HResult = Integer;
  {-----------------------------------------------------------------
  // possible values of HRESULT
  S_OK = 0                    // No error. In some APIs, S_OK indicates a successful operation with a return value of True. 
  S_FALSE = $00000001        // No error, but the operation did not produce a useful result. In some APIs, S_FALSE indicates a successful operation with a return value of False.  
  E_NOINTERFACE = $80004002 // Interface not supported. 
  E_UNEXPECTED = $8000FFFF  // Catastrophic failure. 
  E_NOTIMPL = $80004001     // Operation not implemented. 
  -----------------------------------------------------------------}


  Type TVariantRelationship = (vrEqual, vrLessThan, vrGreaterThan, vrNotEqual);

  function VarType(const V: Variant): TVarType;
  function VarAsType(const V: Variant; aVarType: TVarType): Variant;
  function VarIsByRef(const V: Variant): EvalBool;
  function VarIsEmpty(const V: Variant): EvalBool;
  function VarIsNull(const V: Variant): EvalBool;
  function VarIsClear(const V: Variant): EvalBool;

  function VarIsError(const V: Variant; out AResult: HRESULT): EvalBool;
  function VarAsError(AResult: HRESULT): Variant;

  function VarIsCustom(const V: Variant): EvalBool;
  function VarIsOrdinal(const V: Variant): EvalBool;
  function VarIsFloat(const V: Variant): EvalBool;
  function VarIsNumeric(const V: Variant): EvalBool;
  function VarIsStr(const V: Variant): EvalBool;
  function VarIsArray(const A: Variant; AResolveByRef: EvalBool = True): EvalBool;

  function VarToStr(const V: Variant): string;
  function VarToStrDef(const V: Variant; ADefault: string): string;
  function VarToWideStr(const V: Variant): WideString;
  function VarToWideStrDef(const V: Variant; ADefault: WideString): WideString;
  function VarToUnicodeStr(const V: Variant): UnicodeString;
  function VarToUnicodeStrDef(const V: Variant; ADefault: UnicodeString): UnicodeString;
  function VarToDateTime(const V: Variant): TDateTime;
  function VarFromDateTime(DateTime: TDateTime): Variant;

  function VarInRange(const AValue, AMin, AMax: Variant): EvalBool;
  function VarEnsureRange(const AValue, AMin, AMax: Variant): Variant;
  function VarSameValue(const A, B: Variant): EvalBool;
  function VarCompareValue(const A, B: Variant): TVariantRelationship;

  function VarTypeIsValidArrayType(aVarType: TVarType): EvalBool;
  function VarTypeIsValidElementType(aVarType: TVarType): EvalBool;

  function VarArrayCreate(Bounds: array of SizeInt; aVarType: TVarType): Variant;
  function VarArrayOf(Values: array of Variant): Variant;
  procedure VarArrayRedim(var A: Variant; HighBound: SizeInt);

  function VarArrayAsPSafeArray(const A: Variant): Pointer;
  procedure VarCopyNoInd(var Dest: Variant; const Source: Variant);

  function VarArrayDimCount(const A: Variant): SizeInt;
  function VarArrayLowBound(const A: Variant; Dim: SizeInt): SizeInt;
  function VarArrayHighBound(const A: Variant; Dim: SizeInt): SizeInt;

  function VarArrayLock(const A: Variant): Pointer;
  procedure VarArrayUnlock(const A: Variant);
  function VarArrayRef(const A: Variant): Variant;

  function VarArrayGet(const A: Variant; Indices: array of Int32): Variant;
  procedure VarArraySet(var A: Variant; const Value: Variant; Indices: array of Int32);


woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 28 Nov 2022, 20:00

Can someone put that in a little more context? Like how to use it with getObject?

I tried this:

var st: string;
var v: TVarType;

v := getObject(address);
st := varType(varString);

that's not it. It gives an assignment error (which I would include here if it was possible to select text from the script compile log window.)

but of course it can't work, there's no reference to 'v'. But V is a const in the function, so I can't put a variable there either, can I?

I tried this:
v := getObject(address);
st := VarToStr(v);

and it compiles, but I still don't get the string value out of it, just the number '83' as always. And it doesn't use varType.....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 28 Nov 2022, 21:09

I actually don't need to query the variant for its type, I know it's a string. I just can't figure out how to get its string value.

Edit: It is actually a string value. It's just always equal to '83'.

Edit: I managed to get a different string okay, (YAY!) so there's something else going on....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 29 Nov 2022, 01:18

I do not know what was going wrong. It suddenly started working. Maybe a space in a control name or something??? Anyway, all good now. No need for variants, just getting the string I wanted. suddenly. inexplicably. ;)
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 29 Nov 2022, 08:28

you don't need to use variants explicitly:

Code: Select all

var S : string;

//PROCESS                                                                             
PROCEDURE PROCESS();                                          
BEGIN   
  S := GetObject ( 'patch.myfader' );
  trace(S);
END;

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests