Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Why is TEdit.SelText (FMX) readonly


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: May 1, 2015 1:29 AM Last Post By: Robert [NL] Mit...
Robert [NL] Mit...

Posts: 100
Registered: 5/23/04
Why is TEdit.SelText (FMX) readonly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 27, 2015 2:23 AM
Using XE8 PE.

I try to insert some text into a TEdit component at run time, doing Edit1.SelText := 'xyz'.

However SelText seems to be read-only (defined as: property SelText: string read GetSelText).

Even when the help file is quoting:

Read SelText to determine the value of the selected text. Set SelText to replace the selected text with a new string. If there is no selection, but the edit control has focus, set SelText to insert a new string into the text, at the cursor.
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: Why is TEdit.SelText (FMX) readonly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 27, 2015 2:19 PM   in response to: Robert [NL] Mit... in response to: Robert [NL] Mit...
Robert Mittendorff wrote:

Using XE8 PE.

I try to insert some text into a TEdit component at run time, doing Edit1.SelText := 'xyz'.

However SelText seems to be read-only (defined as: property SelText: string read GetSelText).

Even when the help file is quoting:

Read SelText to determine the value of the selected text. *Set SelText to replace the selected
text with a new string. If there is no selection, but the edit control has focus, set SelText to
insert a new string into the text, at the cursor.*

That seems to be a copy-paste (from the vcl.stdctrls.tedit) error in the documentation. OTOH,
strange that it is read-only in fmx while read-write in vcl.

--
Tom Brunberg
firstname.lastname@welho.com
Robert [NL] Mit...

Posts: 100
Registered: 5/23/04
Re: Why is TEdit.SelText (FMX) readonly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 28, 2015 8:48 AM   in response to: Tom Brunberg in response to: Tom Brunberg
I 've made myself a workaround (not fully tested however):

uses
  System.SysUtils; {for TStringHelper}
 
procedure InsertTextAtCursor(Edit: TEdit; const TextToInsert: string);
begin
    Edit.Text := Edit.Text.Substring(0, Edit.SelStart) + TextToInsert + Edit.Text.Substring(Edit.SelStart + Edit.SelLength);
    Edit.SelStart := Edit.SelStart + TextToInsert.Length;
end;


Tom Brunberg wrote:
Robert Mittendorff wrote:

Using XE8 PE.

I try to insert some text into a TEdit component at run time, doing Edit1.SelText := 'xyz'.

However SelText seems to be read-only (defined as: property SelText: string read GetSelText).

Even when the help file is quoting:

Read SelText to determine the value of the selected text. *Set SelText to replace the selected
text with a new string. If there is no selection, but the edit control has focus, set SelText to
insert a new string into the text, at the cursor.*

That seems to be a copy-paste (from the vcl.stdctrls.tedit) error in the documentation. OTOH,
strange that it is read-only in fmx while read-write in vcl.

--
Tom Brunberg
firstname dot lastname at welho dot com
Robert [NL] Mit...

Posts: 100
Registered: 5/23/04
Re: Why is TEdit.SelText (FMX) readonly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 1, 2015 1:29 AM   in response to: Robert [NL] Mit... in response to: Robert [NL] Mit...
See workaround, now closed
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02