Scintilla controls: set text works only if #NoEnv is on Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 2998
Joined: 19 Dec 2016, 01:58
Location: UK

Scintilla controls: set text works only if #NoEnv is on

19 Nov 2017, 01:34

- I've been working on some functions for getting/setting the text in controls, and I noticed that JEE_SciSetTextAlt and JEE_SciPasteAlt only work if #NoEnv is on.
- They were working in my main script, but not in another script that didn't have #NoEnv set.
- I'm mentioning this in case anyone can figure out why this might happen, or in case it relates to anyone else's issues with a script.
- Warning: JEE_SciSetTextAlt erases any text in the current Scintilla control, and JEE_SciPasteAlt would overwrite the selected text.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jeeswg on 19 Nov 2017, 12:39, edited 1 time in total.
teadrinker
Posts: 303
Joined: 29 Mar 2015, 09:41

Re: Scintilla controls: set text works only if #NoEnv is on

19 Nov 2017, 12:01

Interesting, looks like a bug. However, ControlSetText and Control don't have to work with any controls, as I understand, they are desighned for Windows native controls. For Scintilla there are its messages: SCI_GETTEXT, SCI_SETTEXT, SCI_ADDTEXT. Also, using UTF-8 encoding is not quite correct. The code page can be different, it depends on user preferences, so you need to figure out the code page with SCI_GETCODEPAGE.
User avatar
jeeswg
Posts: 2998
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Scintilla controls: set text works only if #NoEnv is on

19 Nov 2017, 12:07

- Yes, you're right, there is no reason why these methods *should* work, but it happens that they do, if you use #NoEnv.
- I will be sharing some scripts that get/set a Scintilla control's text, in the *right* way, via SCI_GETTEXT and SCI_SETTEXT.
- Thanks for the info re. SCI_ADDTEXT, and I meant to look for something like SCI_GETCODEPAGE so thanks for that as well.
User avatar
Capn Odin
Posts: 1273
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: Scintilla controls: set text works only if #NoEnv is on

19 Nov 2017, 18:44

Try checking if any of part of your script shares a name with an Environment Variable.
Please excuse my spelling I am dyslexic.
Helgef
Posts: 2478
Joined: 17 Jul 2016, 01:02
Contact:

Re: Scintilla controls: set text works only if #NoEnv is on  Topic is solved

19 Nov 2017, 19:56

As per the documentation on varsetcapacity, you need to update the variables internally stored string length, that is, varsetcapacity(vUtf8,-1). Otherwise it is considered a blank variable, and then, if you did not specify #noenv, it will be checked if it is an env. variable, it isn't, and "" is passed to the command. With #noenv specified, the command will just pass on the pointer to the variable's string buffer, which is a null terminated string, in a WM_SETTEXT message to the control. You could also send WM_SETTEXT directly to the control, passing &vUtf8.

Cheers :wave:
User avatar
jeeswg
Posts: 2998
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Scintilla controls: set text works only if #NoEnv is on

19 Nov 2017, 21:12

Great, so to fix it I just needed to add VarSetCapacity(vUtf8, -1) after each StrPut line. Although, just to state again, this was very hacky, and not really the proper way to get/set the text. Since using ControlGetText typically retrieved one character, I tried a few things, hence these 3 functions. The hacky approach is far shorter in lines than the official approach that I will share soon in my control get/set text library.

@Capn Odin: Yes, I had thought that possibly a variable might be an issue, I kept looking up and down the script, but not seeing a candidate variable, and it appears ultimately that there wasn't one.
@Helgef: Cheers. :beer:

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], TXShooter and 40 guests