Is it possible to output text on multiple lines in an OBJ_TEXT object? - page 7

 
Реter Konow:
Of course.

I also want to puzzle you with something that puzzled me.))) Is it possible to pass several individual lines in one resource, so that you can read only the selected line from it while reading the resource.

For an image a few lines can be created through TextOut() but attempts to read such a resource has no success. Only the first line can be read.

 
Alexey Viktorov:

I also want to puzzle you with something that puzzled me.))) Is there a possibility to pass some separate lines in one resource, so that it's possible to read only selected line from it.

For an image a few lines can be created through TextOut(), but attempts to read this resource have failed. Only the first line can be read.

There is no point in trying to save or read text from a picture. Use the resource to write strings as I described above, then extract back using CharArrayToString. Next, split the string by a delimiter and find the right one among them. (Hence, before saving the string, divide it into substrings by some symbol).
 
Реter Konow:
There is no point in trying to save or read text from a picture. Use the resource to write strings as I described above and then extract back using CharArrayToString. Next, split the string by a delimiter and find the right one among them. (Hence, before saving the string, divide it into substrings by some symbol).

I had no desire to read from a picture. I only mentioned the picture as an example of an entry in a few lines.

Pulling out a substring is too easy. We are not looking for easy ways :))) Thanks for the help.

 
Alexey Viktorov:

I had no desire to read from a picture. I only mentioned the picture as an example of a few lines of writing.

To take out a substring, it's too easy. We're not looking for easy ways.) Thanks for the help.

It's not too hard to pull a substring if you already know how to save data in a resource and extract it. This is a simple task in itself. Try saving the string to a resource first and then extracting it from there. Then add a function to break the string into substrings and search for the right one.
 
Реter Konow:
It's not too hard to pull out a substring if you already know how to save data in a resource and retrieve it. It is a simple task in itself. Try saving the string to a resource first and then extracting it from there. Then add a function to break the string into substrings and search for the right one.

Peter thanks for your help. I learned how to work with strings years ago. And how to save a resource and read it, with your help, I figured it out yesterday. Just got a frantic text message in my head, like I should try it... and how to do it the text message got lost on the way, got lost in my thoughts.

I'm trying to figure out the difference between two-dimensional and one-dimensional arrays for creating resources. Do you have any developments, thoughts on this?

 
Alexey Viktorov:

Peter thanks for your help. I learned how to work with strings years ago. And how to save a resource and read it, with your help, I figured it out yesterday. Just got a frantic text message in my head, like I should try it... but how to do it the text message got lost in the way, got lost in my thoughts.

So now I'm trying to figure out the difference between two-dimensional and one-dimensional arrays for creating resources. Do you have any insights, thoughts on this?

To be honest, I've never stored a two-dimensional array in a resource. I've always worked with a one-dimensional one, because it's unconstrained. One-dimensional is better for saving data, although it doesn't have to be. It depends on what kind of data and in what format. Use only a one-dimensional array for string saving, because the two-dimensional array cannot be sent to CharArrayToString and StringToCharArray functions. So, I'd advise you to develop a mechanism to store any of your data in a one-dimensional array for flexibility. But, you can try to use two-dimensional for non-string data of the same type. It will be interesting to see what you get out of it.
 

I read some earlier pages and realized that the task was to read only one small string from the resource. If this string is less than 64 characters, there's no sense in making a mess with unions and saving data to the resource. Just write the required string to description property of OBJPROP_TEXT:

ObjectSetString(chartID,label_name,OBJPROP_TEXT, "Your string");

And get it back like this:

string Str = ObjectGetString(chartID,label_name,OBJPROP_TEXT);


And that's it.))

 
Alexey Viktorov:

Forum on trading, automated trading systems and testing trading strategies

Libraries: TradeTransactions

fxsaber, 2018.09.20 16:23

// Пример хранения/обмена данными через Ресурсы внутри Терминала
#include <fxsaber\TradeTransactions\ResourceData.mqh> // https://www.mql5.com/ru/code/22166

void OnStart()
{  
  const RESOURCEDATA<int> ResourceINT("::int"); // Ресурс для обмена int-ами. const - как доказательство, что ничего не пишется в объект класса
  
  int ArrayINT[] = {1, 2, 3};
  int Num = 5;
  
  ResourceINT = ArrayINT;  // Ресурс хранит массив.
  ResourceINT += Num;      // Добавили в ресурс еще значение.
  ResourceINT += ArrayINT; // Добавили массив.
  
  int ArrayINT2[];  
  ResourceINT.Get(ArrayINT2); // Считали данные из ресурса.
  ArrayPrint(ArrayINT2);      // Вывели: 1 2 3 5 1 2 3

  ResourceINT.Free();                // Удалили данные из ресурса
  Print(ResourceINT.Get(ArrayINT2)); // Убедились, что данных нет: 0

  const RESOURCEDATA<MqlTick> ResourceTicks("::Ticks"); // Ресурс для обмена тиками. const - как доказательство, что ничего не пишется в объект класса
  MqlTick Tick;
  
  if (SymbolInfoTick(_Symbol, Tick))
    for (int i = 0; i < 3; i++)
      ResourceTicks += Tick; // Добавили в ресурс тики

  MqlTick Ticks[];
  ResourceTicks.Get(Ticks); // Считали данные из ресурса.
  ArrayPrint(Ticks);        // Вывели.
  
  // Это полное имя ресурса для обращения из другой программы
  const string NameOut = StringSubstr(MQLInfoString(MQL_PROGRAM_PATH), StringLen(TerminalInfoString(TERMINAL_PATH)) + 5) + "::Ticks";  
  Print(NameOut); // Вывели полное имя ресурса.
  
  const RESOURCEDATA<MqlTick> Resource(NameOut); // Ресурс для доступа к данным (read-only) из другой программы
  
  MqlTick TicksOut[];
  Resource.Get(TicksOut); // Считали данные из ресурса.
  ArrayPrint(TicksOut);   // Вывели.
  
  Resource.Free();   // Не получится повлиять на данные read-only-ресурса.
  Print(_LastError); // ERR_INVALID_PARAMETER - Ошибочный параметр при вызове системной функции.
}

 
Реter Konow:

I read some earlier pages and realized that the task was to read only one small string from the resource. If this string is less than 64 characters, there's no sense in making a mess with unions and saving data to the resource. Just write the required string to description property of OBJPROP_TEXT:

ObjectSetString(chartID,label_name,OBJPROP_TEXT, "Your string");

And get it back like this:

string Str = ObjectGetString(chartID,label_name,OBJPROP_TEXT);


And that's it.))

Not exactly. The task was to output a few lines of information. In my opinion... it's just the way I wanted it to be displayed. One of the lines has a date in it. This date is not only for clarity, but should be used by the program even after the restart. It turns out that it has to be saved somehow. This is where I started messing around, we're not looking for easy ways out. Since one way to save the date is to use a graphical object, why not use the same resource. After restarting MT resource is readable, but after restarting the computer has not checked yet. The main thing is that I figured out resources and units. The next thing I knew, I was getting frantic text messages in my head. Once I've deleted everything, I'll continue the useful work.

 
Alexey Viktorov:

Not really. The task was to output a few lines of information. In my opinion ... that's just the way I wanted it to be, to display it with a canvas. One of the lines has a date in it. This date is not only for clarity, but it should be used by the program even after the restart. It turns out that it has to be saved somehow. This is where I started messing around, we're not looking for easy ways out. Since one way to save the date is to use a graphical object, why not use the same resource. After restarting MT resource is readable, but after restarting the computer has not checked yet. The main thing is that I figured out resources and units. The next thing I knew, I was getting frantic text messages in my head. Once I've deleted everything, I'll continue the useful work.

Good. Then keep mastering resources and unions. They offer a versatile way to not only write and store any data quickly, but also to share that data between different programs in real time and with no load on the disk.

Reason: