Variant String Append << Back

Prior to DF 20.1, there is a limit on the length of all strings. The limit is set by Set_Argument_Size. In VDF 16.1, it is set to 65536 bytes by default. In DF 20.1, DAW has gotten rid of the need of "Set_Argument_Size". This article is for those who still live in the pre DF 20.1 world.

In a recent post, Samuel Pizarro was misled by the DF online help (which was later "corrected") that variant string was not affected by the "Argument_Size" limitation. Alas, variant strings are still affected by "Argument_Size" in the pre DF 20.1 world. Samuel is wondering how he could overcome such limitation. Obviously one could simply jack up the Argument_Size to as big as you need. However I feel like we are solving a local problem with a global solution. To learn more about Argument_Size, please read this excellent blog post written by Sonny Falk (Please come back, pretty please!!!!!) about Argument_Size.

So, here it is, a small global function to allow you to append to a variant string for as long as you like (limited by the memory of the OS, of course). It will work with VDF 11.1+ (I haven't tested anything older than VDF 11.1)

Use UI

External_Function VarBstrCat "VarBstrCat" OLEAUT32.DLL Pointer p1 Pointer p2 Pointer p3 Returns Integer

#IF !@<200

Function AppendV Global Variant v1 Variant v2 Returns Variant
	#IF !@<201
	Pointer p
	Variant v3
	Boolean bOK
	Move v1 to v1
	Move v2 to v2
	If (DeRefW(AddressOf(v1), 0) = 8 and DeRefW(AddressOf(v2), 0) = 8) Begin
		Move 0 to p
		If (VarBstrCat(DeRefPtr(AddressOf(v1), 8), DeRefPtr(AddressOf(v2), 8), AddressOf(p)) = 0) Begin
			Move 0 to v3
			Move (StoreW(AddressOf(v3), 0, 8)) to bOK
			Move (StorePtr(AddressOf(v3), 8, p)) to bOK
			Function_Return v3
	Function_Return (v1 + v2)

Free Web Hosting