// Working with arraysshort Array[] = {1, 2, 3};
ArrayPrint(_R(Array).Bytes); // Print byte-by-byte representation of Array array
PRINT((_R(Array) == _R(Array).Bytes)) // Make sure that byte-by-byte array comparison works.
_W(Color) = Array; // Byte-by-byte write Array array to Color
PRINT(Color) // Make sure Color is now C'1,0,2'.
ArrayPrint(_R(Color).Bytes); // Print byte-by-byte representation of Coloruchar Array2[];
ArrayCopy(Array2, _R(Tick).Bytes); // Write the byte representation of Tick to Array2
PRINT((_R(Tick) == Array2)) // Make sure that Tick and Array2 match byte by by byteMqlTick Tick2 = {0};
_W(Tick2) = Array2; // Write Array2 array to Tick2
PRINT((_R(Tick) == Tick2)) // Make sure that Tick and Tick2 match.int Array3[] = {INT_MIN, INT_MAX};
ArrayPrint(_R(Array3).Bytes); // Print byte-by-byte representation of Array3 array
ArrayPrint(_R(Array).Bytes); // Print byte-by-byte representation of Array array
_ArrayCopy(Array3, Array); // Copy Array array to Array3 array byte by by byte
ArrayPrint(_R(Array3).Bytes); // Make sure that the byte representation of the Array3 array matches the
// Working with stringsstring Str = "abcd";
_W(i) = Str; // Write the string to (int)i byte by byte
PRINT((_R(i) == Str)) // Byte-by-byte comparison of int and sring
ArrayPrint(_R(i).Bytes); // Looked up bytes i
ArrayPrint(_R(Str).Bytes); // Looked at Str bytes
PRINT(_R(Str)[(short)1]) // Took the short-value by mix 1 in Str
PRINT(Str)
_W(Str)[2] = "98765"; // Byte-by-byte writing of a string to a string at offset 2
PRINT(Str)
string StrArray[] = {"123", "45", "6789"};
_W(Str) = StrArray; // Write a string array to a string
PRINT(Str)
_W(Str)[3] = (uchar)0; // A zero is written to byte at offset 3, thus cutting off the string (length - 3 ANSI characters (4 bytes)).
PRINT(Str);
// Set a custom structurestruct STRUCT
{
int i;
// Set the assignment operatorvoidoperator =( const STRUCT& ) {}
};
// Demonstration of the result of bypassing the custom assignment operator of the _R structure by the library function
STRUCT Struct; // Created an object with a custom assignment operator
Struct.i = 1;
ArrayPrint(_R(Struct).Bytes); // Make sure that the assignment operator
PRINT(_R(Struct) == Struct) // does not affect the _R functionality of the library// Checking the "correctness" of the type assignment operator
PRINT(_WRONG_ASSIGN_OPERATOR(int)) // Correct
PRINT(_WRONG_ASSIGN_OPERATOR(MqlTick)) // Correct
PRINT(_WRONG_ASSIGN_OPERATOR(STRUCT)) // Not correct
Color = (color)((Color & 0xFFFFFF) + (Alpha << 24));
_W(Color)[3] = Alpha;
Forum on trading, automated trading systems and testing trading strategies
Any newbie questions on MQL4, help and discussion on algorithms and codes
fxsaber, 2017.03.07 13:55
template <typename T>
void Swap( T &Value1, T &Value2 )
{
const T Tmp = Value1;
Value1 = Value2;
Value2 = Tmp;
}
// Sort an array of any simple type
template <typename T>
bool MyArraySort( T &Array[] )
{
if (!ArraySort(Array))
{
const int Size = ArraySize(Array);
for (int i = 0; i < Size - 1; i++)
{
const T Tmp = Array[i];
for (int j = i + 1; j < Size; j++)
if (_R(Tmp) == Array[j]) // TypeToBytes.mqh
{
Swap(Array[i + 1], Array[j]);
i++;
}
}
}
return(true);
}
Forum on trading, automated trading systems and testing trading strategies
Libraries: File Mapping without DLL
fxsaber, 2017.04.03 16:07
Thanks to the author for the library!
I made functions for transferring any data. Below script shows their work on the example of ticks
Result
An example of possible practical application of innovations.
Highlighted - the same result in vastly different ways
An example of how this feature can be useful for detecting potential errors.
Write and run the script.
Result.
_WRONG_ASSIGN_OPERATOR(STRUCT) = trueThis indicates that the assignment operator will not copy a structure into a structure of the same type.
If we add more to the structure,
the result will be the same.
It would seem that by fixing this operator to
should make everything correct, but the library says otherwise.
Perhaps, this is the most subtle point of this example.
We fix it to
and we get the result
_WRONG_ASSIGN_OPERATOR(STRUCT) = falseNow the copy operator is written correctly!
You can check the correctness of assignment/copy operators of any simple structures in a similar way.
Result
A NULL string has zero length in bytes. An empty string is 1 byte long (where zero is the end of the string).