Ecere SDK/eC Forums https://ecere.org/community/ Print view |
|
How to access variables ? https://ecere.org/community/viewtopic.php?f=1&t=357 |
Page 1 of 1 |
Author: | nicktick [ Tue Apr 16, 2013 10:00 pm ] |
Post subject: | How to access variables ? |
Code: Select all
|
Author: | jerome [ Tue Apr 16, 2013 10:07 pm ] |
Post subject: | Re: How to access variables ? |
Hi nicktick, I'm not sure what you are trying to do here. First you are missing a semicolon after: Label label_1 { ... } ; Then, inside those brackets for the label you are setting the values for the Label members of label_1. You cannot use 'this.' here , you are not inside a method. Also, in eC you should avoid using 'this.' anywhere, unless you must resolve an ambiguity (which you are better off avoiding in the first place). Note: you can use code=eC for the tags on the forums to get syntax highlighting. Code: Select all
Regards, -Jerome |
Author: | jerome [ Tue Apr 16, 2013 10:13 pm ] |
Post subject: | Re: How to access variables ? |
Hi nicktick, did you just edit that post, or did I miss the TestFunction()? You cannot add new methods to instances, you can only override virtual methods. If the method is a regular virtual method (e.g. virtual void OnMyVirtualMethod() -- This is for derivative controls to modify the behavior of 'this' control ) and the control has set its master to 'this' (The 'test' class). Then you can do inside TestFunction: Code: Select all
Usually a parameter is included specifying the control generating the event, e.g.: Code: Select all
Code: Select all
Code: Select all
|
Author: | nicktick [ Tue Apr 16, 2013 10:33 pm ] |
Post subject: | Re: How to access variables ? |
Code: Select all
|
Author: | jerome [ Tue Apr 16, 2013 10:39 pm ] |
Post subject: | Re: How to access variables ? |
Hi nicktick, 1. Never change anything in OnRedraw. Only render the current state. Change things elsewhere. Here you are overriding OnRedraw, which is a virtual method of the Label. 'this' represents the label itself. (Typically, virtual methods are not meant to be overridden at the instance level. Events are what is meant to be overridden at the instance levels, and inside them 'this' will be the master, i.e. your TestWindow) Also, you have a typo , you wrote TestWindow 'TestWinow' without the d. And x,y in OnMouseMove is not a delta, it is the coordinates of the cursor in the client space of your window. You also need to invoke Update() for OnRedraw() to get called (and before calling Update(), that is normally where you would change something). -Jerome |
Author: | nicktick [ Tue Apr 16, 2013 11:00 pm ] |
Post subject: | Re: How to access variables ? |
I clicked the OnRedraw() method of label1 from IDE Methods window, then the IDE jumped to the definition of label1. so I didn't recognized that I couldn't change OnRedraw() there, but the IDE didn't give me any message on preventing me modifying itself. how can I tell the label1 to update its position from a method of class TestWindow(and it will let the label1 aware of its position changed) ? I think that if I could add a custom event(event_a) to class Label, then I could fire event_a in method of class TestWindow, is it a workable way ? or what are the best way to reach the goal? since I will use some labels, so how can I custom the class Label to got the above goal ? |
Author: | jerome [ Wed Apr 17, 2013 12:15 am ] |
Post subject: | Re: How to access variables ? |
Hi nicktick, You can override OnRedraw at the instance level (because it is a virtual method). However, that is not the typical usage. Typically for controls, the events are overridden at the instance level, while a class is derived to further customize the behavior of the control and override non-events virtual methods (On*). To change the position of a label, just say label.position = { new position }. A Label shouldn't care what its position is, it gets rendered wherever it is positioned. 'OnPosition' is the virtual method that is invoked when a Window is repositioned. But as stated above, instances of controls should not need to override non-events virtual methods. I don't really know what you are trying to accomplish here, so it's hard to suggest the best approach. |
All times are UTC-05:00 | Page 1 of 1 |
Powered by phpBB® Forum Software © phpBB Limited |