My approach. The core is the engine. - page 60

 
Igor Makanu:

...

But if you know how the event model works in Windows and have had experience of working with compilers with form designers, then everything is the same everywhere

ZS: it's the third time I've seen Sharp, but I've had great experience with Delphi, I don't see the difference at all, everything works the same way, what doesn't work, is googled the first time

I don't remember how the Windows event model works. And have had experience with compilers and designers for a long time.

I need to connect a created form to a MT application and solve a problem. You said it was easy.

 
Georgiy Merts:

By not showing it, but by describing its principles quite clearly. That's what they object to, that's what they say: "the road is wrong".

Moreover, it is "wrong" not for the author, but for those who object. They have chicken-like brains and cannot remember where and what objects they created, where and who refers to them, what each cell in the array means, where they can be changed from and where they cannot... It's understandable that opponents are outraged. Instead of training their memory, so that they could easily memorize a couple thousand objects and references in the program, silly people cut their own access rights, define some distinctions, some interfaces, some polymorphic functions... They torture themselves, like under the Tsarist regime, eh...

Shake off the nonsense about coolness of memory. Sometimes it is observed that the thread of this forum dialogue is not tracked to the depth of two pages. Besides there is too much denial, for the memory to work so wonderfully, as they try to tell us.

 
Dmitry Fedoseev:

Help me solve a problem.

  1. We need to send the event of pressing buttons and checkboxes to MT5.
  2. We need to programmatically change the state of a checkbox or button in a form.
How to do it?
 

The Windows form is there. It starts up and works. Buttons and checkboxes are clickable.

Now need a DLL to connect to MT5. Who knows how to do this?

 
Реter Konow:

Help me solve a problem.

  1. We need to send the event of pressing buttons and checkboxes to MT5.
  2. We need to programmatically change the state of a checkbox or button in a form.
How to do it?

2. Yesterday Igor showed an example. It shows how in the Expert Advisor you can call the method of a class, contained in the imported dll. That is, you need to write a function (method) in c# which changes the state of the checkbox. How to change checkbox property, I don't remember the name of the method, it is easy to navigate by the dropdown list, you have to enter the name of the checkbox, press a dot...

1. I don't know. Probably not. You have to call a dll function from the timer and look at the state of checkboxes. And as for events like button presses, we could probably create an array and store events in it. But it's not hard, considering the advantage of working with controls visually.

 
Реter Konow:

Installed C#. Opened a project. Made a form and added two buttons and three checkboxes to it.

Here is the code in the editor:

Question: Why is there a function for one button and where are the functions for the second button and the checkboxes?

Found this code:

How to use it for interfacing with MT5?

You need to demonstrate that the second button is needed - make a double click on it, and then the code will open and the function will be added. The project will compile with an error if the button is then removed from the form, the code should be manually deleted from some file, but not the one you wrote.

 
Dmitry Fedoseev:

2. Yesterday, Igor showed an example. The example shows how an Expert Advisor can call a method of a class in the imported dll. That is, you need to write a function (method) in c# that changes the state of the checkbox. How to change checkbox property, I don't remember the name of the method, it is easy to navigate by the dropdown list, you have to enter the name of the checkbox, press a dot...

1. I don't know. Probably not. You have to call a dll function from the timer and watch the state of checkboxes. And as for events like button presses, I suggest making an array and stacking the events in it. But it's not hard, considering the advantage of visual handling of controls.

Ok.

So, we need to:

  1. Create a DLL.
  2. Connect it to the widow application with form.
  3. Write methods to translate the events of pressing the buttons and checking boxes in the dll.
  4. Write methods that change the state of buttons and checkboxes in the widow application.
  5. Create shared memory in the dll. So that when accessing from MT5 the flag of state change for buttons and checkboxes is set. Then the Windows application accesses the shared memory, reads flags and uses them to know the state of one or another form element to be changed.
  6. Write cyclic reference to DLL from timer in MT5 for reading flags of function calls or entering text into fields.

    What if there are hundreds of elements?

    How to organize shared memory?

    What if it is necessary to change not only pressed/released state of elements in a form, but also their colour (for example, for buttons)?

    What if you need to change text in input fields in a form programmatically from MT5?


     
    Dmitry Fedoseev:

    As for events such as button presses, it's probably best to make an array and store the events in it. But it's not hard, considering the advantage of visual work with controls.

    I used to do it in a simpler way:

    1. The user pressed the button on the form - the event handler OnClick() was clicked and Button1.Disable was created;

    2. then it is up to MT5 how the exchange will be organized there, I like button clicks to be interrogated in OnTick() - you won't do anything until there is no tick; you can set a neutral value of about 300 ms in the timer - neither a user will notice a frizz, nor MT5 will slow down


    But the point of my example is that the panel visualization in MT5 is now possible in 2 clicks, button handlers work in a .dll, and part of the interface script can be transferred to a form, the same tables, data handling... everything

    most valuable thing is saving time on rendering development, with help of form designer everything is done in hours ;)


    Rehtag Konow:

    Create a shared memory in DLL. So, when accessing from MT5, the flag of state change of buttons and checkboxes will be set. The application accesses shared memory, reads flags and knows that state of one or another form element should be changed.

    Write cyclic reference to DLL from timer in MT5 for reading flags of function calls or entering text into fields.

      And if there are hundreds of elements?

      How to organize shared memory?

      You are going in the wrong direction again, get out of the shaggy 2000s! .... though somehow I think that 2000s is not the limit for you ))))

      no offence, i hope?

       
      Igor Makanu:

      I used to do it in a simpler way:

      1. User pressed the button on the form - immediately entered OnClick() handler, made Button1.Disable there;

      2. then it is up to MT5 how the exchange will be arranged; I like button clicks to be interrogated in OnTick() - anyway, until a tick is not reached, you can set a neutral value of about 300 ms in the timer - neither a user will notice a frizz, nor MT5 will slow down


      But the point of my example is that the panel visualization in MT5 is now possible in 2 clicks, button handlers work in a .dll, and part of the interface script can be transferred to a form, the same tables, data handling... everything

      the best part is saving time on rendering, with the Forms Designer everything is done in hours ;)


      You are going in the wrong direction again, get out of the shaggy 2000s! .... though I think the 2000s is not the limit for you ))))

      No hard feelings, I hope?

      No offence, but it's a pity it's not on point.

      You're taking the NEAREST example and extrapolating from it, believing that complexity will not increase. This is a mistake.

      Even the simplest example you gave is wrong. Because in addition to created form, you also need to create a DLL. And then create a TOTAL memory inside the DLL.

      As the number of form elements grows and the functionality of the program on MT5 becomes more complex, this interaction becomes HEAVILY busy and complicated.

      I have tested all this in practice.

       
      Реter Konow:

      OK.

      So it's necessary to:

      1. Create a DLL.
      2. Connect DLL to Windows application with a form.
      3. Write methods that translate events of pressing buttons and checkboxes into dll.
      4. Write methods to change state of buttons and checkboxes in the widow application.
      5. Create shared memory in the dll. So that when accessing from MT5 the flag of state change for buttons and checkboxes is set. Then the Windows application accesses the shared memory, reads flags and uses them to know the state of one or another form element to be changed.
      6. Write cyclic reference to DLL from timer in MT5 for reading flags of function calls or entering text into fields.

        What if there are hundreds of elements?

        How to organize shared memory?

        What if it is necessary to change not only pressed/released state of elements in a form, but also their colour (for example, for buttons)?

        What if we need to change the text in entry fields of a form programmatically from МТ5?


        If events are handled correctly, then the number of controls is not a problem. In dll, we can create an array or two arrays, one for the object name and the second for the event type. In dll write a function with two parameters, also event name and type. From each desired event handler, call this function, so that the events are placed in arrays. Another method - to track events from EA timer, as convenient or as it turns out - the same arrays by reference or whatever and also a variable - with the number of events in the array. After the call of that method, the arrays are cleared.

        Or maybe it's easier to handle one array; there is an object-event in c#, so I can turn them into an array. Also, maybe it's possible to somehow fiddle around and not to call a function from each event handler by itself. But it doesn't matter; in any case it is a trifle compared to interface capabilities and all the power of c#.

        Reason: