минимальный код:
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.UIConsts, System.Classes,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Objects, FMX.TextLayout;
type
TForm1 = class(TForm)
Text1: TText;
procedure Text1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
procedure Text1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
procedure Text1Painting(Sender: TObject; Canvas: TCanvas;
const ARect: TRectF);
procedure FormCreate(Sender: TObject);
private
Range: TTextRange;
function TextLayout: TTextLayout;
public
function GetSelectedText: string;
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.FormCreate(Sender: TObject);
begin
Text1.AutoCapture:=True;
end;
type
TTextAccess = class(TText);
function TForm1.TextLayout: TTextLayout;
begin
Result:=TTextAccess(Text1).Layout;
end;
function TForm1.GetSelectedText: string;
begin
Result:=Text1.Text.Substring(Range.Pos,Range.Length);
end;
procedure TForm1.Text1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
Range.Pos:=TextLayout.PositionAtPoint(PointF(X,Y));
Range.Length:=0;
Text1.Repaint;
end;
procedure TForm1.Text1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Single);
begin
if Text1.Pressed then
begin
Range.Length:=TextLayout.PositionAtPoint(PointF(X,Y))-Range.Pos;
Text1.Repaint;
end;
end;
procedure TForm1.Text1Painting(Sender: TObject; Canvas: TCanvas;
const ARect: TRectF);
begin
Canvas.Fill.Color:=claSilver;
Canvas.Fill.Kind:=TBrushKind.Solid;
for var R in TextLayout.RegionForRange(Range,False) do
Canvas.FillRect(R,0,0,AllCorners,1);
end;
end.
textselected.zip