How to do the reverse conversion? (from string to structure)
conststring Str = DATA_STRING::ToString(a); // Translated the structure into a string.
str_Message Tmp[1];
// Get an array of structures from the stringif (DATA_STRING::FromString(Str, Tmp))
{
ArrayPrint(Tmp);
Print(Tmp[0].str[]);
Print(_R(Tmp) == a); // Verify that the data matches the original data.
}
// Get the structure from the string.// Tmp[0] = DATA_STRING::FromString<str_Message>(Str); // This is possible if there is no assignment operator (see STRING120::operator =).
I have written a function to save strings of any length to global variables using your library. I don't understand everything, so I'm sure I haven't used it 100%.
Any thoughts on more efficient use?
#include <TypeToBytes.mqh>
//--------------------------------------------------------------------------------------------------string
GVarGetString(string name) {
double dbl[];
// Read the parts of the variable: Name, Name(1), Name(2), ...for (int i = 0; ; ++i) {
string s = (i == 0)? "" : "(" + (string)i + ")";
double t = GlobalVariableGet(name + s);
if (t == 0)
break;
MyArrayResize(dbl, i + 1);
dbl[i] = t;
}
uchar tmp0[], tmp[], tmp1[];
_ArrayCopy(tmp0, dbl);
if (tmp0[0] != 0)
// UncompressedreturnCharArrayToString(tmp0);
else {
// With compressionArrayCopy(tmp, tmp0, 0, 1);
CryptDecode(CRYPT_ARCH_ZIP, tmp, tmp1, tmp1);
returnCharArrayToString(tmp1);
}
}
//--------------------------------------------------------------------------------------------------void
GVarSetString(string name, string val) {
double dbl[];
uchar tmp[];
uchar zero[1];
int cnt = CryptEncode(CRYPT_ARCH_ZIP, _R(val).Bytes, tmp, tmp);
if (cnt >= StringLen(val)) {
// Uncompressedstring str[1];
str[0] = val;
_ArrayCopy(dbl, str);
}
else {
// With compression
_ArrayCopy(dbl, zero, 0, 0, 1); // Byte[0] == 0 - with compression
_ArrayCopy(dbl, tmp, 1); // From byte[1] data
}
// Write the parts of the variable: Name, Name(1), Name(2), ...
cnt = ArraySize(dbl);
for (int i = 0; i < cnt; ++i) {
string s = (i == 0)? "" : "(" + (string)i + ")";
GlobalVariableSet(name + s, dbl[i]);
}
GlobalVariablesFlush();
}
и динамическое формирование имени массива не обязательно строкового. Отдельный тип глобальных переменных - скорее всего не добавят. таким образом можно записывать и считывать из глобальных переменных строки
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
The code converts a structure to a string
How to do the reverse conversion? (from string to structure)
The code converts the structure to a string
How to do the reverse conversion? (from string to structure)
The yellow line of code does not compile anymore. It gives the following error (build 2980):
Any ideas what would solve the problem?
The yellow line of code does not compile anymore. It generates the following error (build 2980):
Any ideas what would solve the problem?
Forum on trading, automated trading systems and testing trading strategies
Libraries: SingleTesterCache
fxsaber, 2021.06.21 02:42 pm.
In TypeToBytes.mqh, replace {0} with {} everywhere.
Updated. Bypasses a feature that was found. Previously could negatively affect _ArrayCopy and CONTAINER.
I have written a function to save strings of any length to global variables using your library. I don't understand everything, so I'm sure I haven't used it 100%.
Any thoughts on more efficient use?
Any thoughts on more efficient use?
Check out this option.
It would also be convenient to use CONTAINER<double> for global variables .
Check out this option.
It would also be convenient to use CONTAINER<double> for global variables .
Thanks