Archive
Creating an edit-box in Smart Pascal
Under HTML5 there is a special property that you can add to any suitable tag, such as the DIV tag, to make the content editable. In other words you are no longer bound to the restrictions of text-fields and memo-fields as was the case earlier.
Since the Smart Pascal RTL (VJL, visual javascript library) is architected to create, maintain and keep track of controls in the DOM (document object model) – with a 1:1 mapping of functionality, adding support for editable elements is fairly straight forward. But you need to know you way around HTML5 and JavaScript.
Setting up the target
All components and controls in Smart Pascal has a method called StyleTagObject(), this method is called at the beginning of the constructor (after the element has been created and a handle-reference is obtained) so the user, which is you and me, can set properties and values before the html element is finalized and made visible.
Note: You can set properties and attributes at any time, but it makes sense to alter the different values before the component becomes visible. This is why I added StyleTagObject() to the construction sequence.
Turning an element editable is very easy. Simply override the StyleTagObject() method as such:
procedure TMyControl.StyleTagObject; Begin inherited; w3system.w3_setAttrib(handle,'contenteditable',True); end;
In this case we alter the html-element property “contenteditable” to true, which depending on the element, turns the object into a text-editor. Since TW3CustomControl is set to create a DIV element by default (this can be altered easily as well) the result is something that looks like a normal memo editor in Delphi. But without any scrollbars of course.
You may also want to add a call to setFocus() in the mouseDown events if you are building a composite control (e.g an editor, scrollbars and other stuff inside a custom control).
And that’s how easy it is to play with the DOM and create an editable custom HTML5 control!
Recent
The vatican vault
- March 2023
- February 2023
- December 2022
- October 2022
- January 2022
- October 2021
- March 2021
- November 2020
- September 2020
- July 2020
- June 2020
- April 2020
- March 2020
- February 2020
- January 2020
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- September 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- February 2013
- August 2012
- June 2012
- May 2012
- April 2012