Using objects to change the extern variable - page 2

 
fxsaber:


PS Read this topic.

PS Read further into the thread

 
Ernst Van Der Merwe:

Here's a simple example:

click the text once, right-click change value, and click again.

I'm curious... why don't you use the wrappers in the standard library? They would make your life so much easier... 


#property strict
#property indicator_chart_window
//--- input parameters
extern int      inpValue = 20;

#include <ChartObjects\ChartObjectsTxtControls.mqh>
CChartObjectLabel label;

int OnInit()
{
   if(!label.Create(0, "__label__", 0, 100, 100)
      || !label.FontSize(inpValue)
      || !label.Color(clrRed)
      || !label.Description(string(inpValue))
   )
      return INIT_FAILED;
   return INIT_SUCCEEDED;
}

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   if(id == CHARTEVENT_OBJECT_CLICK && sparam == label.Name())
   {
      inpValue++;
      label.FontSize(inpValue);
      label.Description(string(inpValue));
   }
}

int start(){ return 0; }
 
nicholi shen: I'm curious... why don't you use the wrappers in the standard library? They would make your life so much easier... 

Probably because, some people do not like using the standard library (myself included). We don't trust it and so use our own.

Also, in order for the newbie coder to understand the procedural functionality behind things, using the library does not really help teach them this.

Besides, most newbies do not understand OOP coding anyway and are still trying to wrap their heads around the basics.

 
nicholi shen:

I'm curious... why don't you use the wrappers in the standard library? They would make your life so much easier... 

It's funny you mention this because I started playing with the ChartObjectsTxtControls standard library just last Saturday. I actually found an example of yours ( @nicholi shen ) on a different Forum that I used as a template.

I suppose the reason I haven't used ChartObjects library until now is that I didn't know about it. By that I mean that I didn't know about this standard library when I built my own GUI class. Maybe this library didn't exist when I wrote my GUI code—I couldn't really say. I don't read documentation from cover to cover. When I happened upon the ChartObjects standard libraries (a few months ago), I had no pressing reason to replace existing code. So I put it on the back burner for a future project.

On Saturday, I was researching the best way to build a dashboard for a project I am thinking about. Turns out I will probably use the Controls standard library for that purpose rather than building it from discrete graphical components, as I have done in the past.

I like the ChartObjects library for writing clean code, and I may use it going forward, but for the moment I don't have a pressing need since I already have rolled my own class similar to it.

 
Fernando Carreiro:

Probably because, some people do not like using the standard library (myself included). We don't trust it and so use our own.

Also, in order for the newbie coder to understand the procedural functionality behind things, using the library does not really help teach them this.

Besides, most newbies do not understand OOP coding anyway and are still trying to wrap their heads around the basics.

Well I think we can all agree that the most fundamental basic building block of all the programming concepts is the DRY principal (Don't Repeat Yourself).  Also, OOP is a basic fundamental concept of all major languages (including MQL) with the exception of C. That being said, creating and using chart-objects using the low-level MQL functions is a violation of the DRY principal. I'm not sure who you are referring to when you use the pronoun "we", but this is the first time I've ever seen anyone say that they do not trust the chart object wrappers included in the standard library. I'm not sure what's not to trust about a well written library that wraps the low-level functions you intend noobs to use in the first place... ?


Turns out I will probably use the Controls standard library for that purpose rather than building it from discrete graphical components, as I have done in the past.

Good choice. I'm sure you are aware that there are two libraries for chart objects. Controls are intended for adding control elements to CAppDialog, and ChartObjects are intended for everything else related to adding chart-objects to charts. 

 
nicholi shen:

Well I think we can all agree that the most fundamental basic building block of all the programming concepts is the DRY principal (Don't Repeat Yourself).  Also, OOP is a basic fundamental concept of all major languages (including MQL) with the exception of C. That being said, creating and using chart-objects using the low-level MQL functions is a violation of the DRY principal. I'm not sure who you are referring to when you use the pronoun "we", but this is the first time I've ever seen anyone say that they do not trust the chart object wrappers included in the standard library. I'm not sure what's not to trust about a well written library that wraps the low-level functions you intend noobs to use in the first place... ?

I say "we", because I personally know of at least 3 people that think the same way and this has been stated before on the forums.

I say "trust" because there have been problems in the past with the OOP library.

I am also not anti-OOP as I also stated that I use my own libraries.

I just believe that for beginners, procedural programming is easier for them to understand, and then in time they can evolve onto OOP.

 
Fernando Carreiro:

I say "we", because I personally know of at least 3 people that think the same way and this has been stated before on the forums.

I say "trust" because there have been problems in the past with the OOP library.

I am also not anti-OOP as I also stated that I use my own libraries.

I just believe that for beginners, procedural programming is easier for them to understand, and then in time they can evolve onto OOP.

I've thoroughly test the STL with regards to ChartObjects and there is a problem with some of the Load/Save methods in MT4 due to it being ported over from MT5. That said 99% of devs here will never use the Load/Save methods in MT4 so it's not an issue. 

Reason: