Visualize gradient on a line at runtime

  

I’m trying to create a Tline Shape at runtime and assign a gradient without success. When creating other shapes such as circles or squares, no problem appears.

Note: At design time, a Tline shape does the gradient. I’m using Tokyo version 10.2

unit Unit1;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.FormCreate (Sender: TObject);
var
DLine : TLine;
begin
DLine := Tline.Create (nil);
DLine.Position.x := 100;
DLine.Position.y := 100;
DLine.Height := 300;
DLine.LineType := TLineType.Left;
DLine.Stroke.Thickness := 3;
DLine.Fill.Gradient.Color := $FF0000FF; // Blue
DLine.Fill.Gradient.Color1 := $FFFF7F50; // Coral
DLine.Fill.Kind := TBrushKind.Gradient;
DLine.Fill.Gradient.Style := TGradientStyle.Linear;
DLine.Parent := Form1;
end;

end.

Comments are closed.