TMSFMXMemo Position and Line Text Issue

TMSFMXMemo version
XE7 Rad Studio

I am converting an existing program from using the Rad Studio built-in TMemo component to using your TMSFMXMemo component. I have two issues.

First Issue. I need to pass the text of a specific line to an ANSI C function for further processing. Using the built in TMemo, I was converting the current line of text using

(note that Editor is the name I renamed the TMemo component and the TMSFMXMemo component)

AnsiString ansiline;
ansiline = Editor->Lines->operator /* Editor is the TMemo component /

The TMSFMXMemo component does not have the CaretPosition type using CurX and CurY instead.

My question is how do I grab the just the line of text at CurY?

Second issue is I need to convert the CurX and CurY position into an absolute character position. The manual shows two functions PosFromText an TextFromPos but neither seems to exist. My previous version that used TMemo worked as such:

int cp; /
character position in the text file /
cp = Editor->PosToTextPos(Editor->CaretPosition); /
Editor is the TMemo component */

Again, TMSFMXMemo does not have the CaretPostion type, combined with not finding the other two operations.

My question how do I convert CurX and CurY into the actual byte offset position from the start of the file to the current cursor position? or what method do you recommend?

After rebooting my brain, I figured out part of this

To grab a specific line from TMSFMXMemo to send to an ANSI C function

(Note: Editor is what I named the TMSFMXMemo component)

AnsiString ansiline; /* declare a C++ TString /
ANSI C string /

ansiline = Editor->Lines->operator; /
get the string converted from Unicode to ANSI /
strcpy(ts, ansiline.cstr()); /
copy the string to the standard C pointer */

Regarding my second question about getting the absolute position. I somehow missed seeing in the long drop-down list of available procedures the two operations. However I am having trouble getting the TextFromPos to work correctly.

I keep getting errors on the third parameter.

Could you give me an example of how to use those two procedures?

ok. got it to work

int i;
Editor->TextFromPos(Editor->CurX, Editor->CurY, i); /* Editor is TMSFMXMemo component */

However, given the following text lines in the TMSFMXMemo


if the cursor is between g and h, i has the value of 7. correct
if the cursor is after h, i has a value of 8. correct
if cursor is at the start of second line (before i) then i has a value of 10 implying two characters for a line termination.

Looking at the actual dump in the watch pane show a string of
"ijklmnop" as a null terminated string, which is correct
same for the first line "abcdefgh" with a null character termination
assuming a termination character (either null or '\n') the count should be 9 not 10


There is a function to get the word at the X and Y caret position, so you can retrieve the text at that specific position:

s := TMSFMXMemo1.WordAtXY(TMSFMXMemo1.CurX, TMSFMXMemo1.CurY);

Kind Regards,