Edit Field Widget
OBJ_EDIT has no per-keystroke event on either platform. The terminal fires exactly one event, CHARTEVENT_OBJECT_ENDEDIT, when the user presses Enter or clicks elsewhere. Reading OBJPROP_TEXT before that event returns whatever was in the field before the user started typing, not what is currently on screen - which means validation can only ever happen at ENDEDIT time, never earlier. Code that does not know this reads a stale value, assumes it just parsed the user's input, and quietly acts on the previous number. This widget makes ENDEDIT the single point where correctness is enforced. EndEdit() checks the new text against an optional maximum length and an optional numeric-only flag set once in Create(). A violation is not left on screen as a silently-broken value - the field is snapped back to the last value that was actually accepted, so an invalid edit is visibly undone rather than invisibly ignored. The numeric check is deliberately narrow: digits, one optional leading sign, one optional decimal point. It rejects "12x" and a lone "-" or "." typed and left mid-entry, without pulling in a general-purpose number parser for what is fundamentally a keyboard filter. GetDouble() and GetInteger() read from the last accepted value, not from OBJPROP_TEXT directly, so a caller can never observe the field in a half-typed state. SetEnabled() reuses OBJPROP_READONLY plus a greyed background rather than inventing a separate disabled concept, matching the same contract every other widget in this catalogue exposes. The header is self-contained - one class, no dependency on WidgetLabel, ChartObjects or PanelFramework from this collection. Notes and limitations - Validation happens only at ENDEDIT, because that is the only moment either platform gives you. There is no way to reject a keystroke as it is typed. - The numeric check accepts a syntactically valid number, not a number in any particular range - clamp the parsed value yourself if you need min/max. - The demo cannot generate a real keystroke-then-Enter sequence, since a script's OnStart runs once with no live event loop. It sets OBJPROP_TEXT the way typing would leave it, then calls EndEdit() directly, which exercises the identical validation path a genuine ENDEDIT event would use. - One widget instance owns exactly one chart object. A form needs one CEditWidget per field.
Script · MT4 · v1.0 · Free
About Edit Field Widget
Edit Field Widget is a script for MetaTrader 4. It has 1 setting, such as Prefix. MQL source code included.
Files in the download: WidgetEdit.mqh, WidgetEdit.txt, WidgetEditDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Prefix | WidgetEditDemo_ | Object-name prefix, avoids collisions on re-run |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: MT4 Script · MQL4 Source Code