A good copy …
Today i again looked a little bit closer on the Memo component and include some features:
Copy/Paste/Cut/Undo can be called from Program.. not only from the keystrokes already defined in the texteditor component. Additionally the Caret position can be read (Row and Line position) the justification of text can be changed to left, right or center.
seems there is no direct way to mark a text part (just a strange way I currently do not understand) and even NO way to read out what is selected at the moment. so selStart, selLength will be hard to implement
I really think about to replace the EditBox by this TextEditor Component… just limit it to one line.. only some minor changes must be done for it, perhaps later I will try.
Hello again…
A suggestion about selStart and selLength…
As I can see, you can copy the selected text? I guess it goes to a clipboard?
Why not backup content in clipboard, make a copy of the selected text, read out how many chars is selected, then get caretPos, search from line:like [dont remember the argOrder now] str:=copy(srchStr, bodyString, caretPos-length(clipboardText)… and the same but in a positive direction… then concat the two strings and scan for the text in the clipboard
like: (pseudocode)
buffer:=clipboard
clipboard:=selected Text // (or copy command)
clipStr:=clipBoard
clipBoard:=buffer
clipLen:=length(clipStr)
line:=TMemo.Lines[caretPos.y]
hStr:=copy(line,caretPos.x-clipLen) //get a neg entry from caretpos
tStr:=copy(line,caretPos.x+clipLen) //get a pos entry from caretpos
mStr:=hStr+tStr
//now in this mStr search for the word in clipStr and calculate the selStart value and selLength value of clipStr
however that require an mechanism to detect if text has been selected or not…
In principle a good solution but it does not always work.. I also thought about to do it in this way.
BUT:
the Text looks like
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
from clipboard I know the User marked „aaa“ CaretPos = 5
so which aaa it is? before or after?
Even from knowing the caret position its still impossible to get the real selected position.
(ok the sample is rather crude… 😉 but you must expect such cases.. especially if you only select one char you will get it. „between“ -> which „e“ is marked if caret is between?)