Home > Blockchain >  Trying to make a slider but i keep getting incompatible types
Trying to make a slider but i keep getting incompatible types

Time:09-13

I'm trying to make a Slider in Delphi, but I keep getting errors:

Incompatible types 'TPoint' and 'TPointF'

Incompatible types 'Integer' and 'Single'

Incompatible types 'Integer' and 'Extended'

I don't know why I'm getting these errors.

procedure TForm1.FormTouch(Sender: TObject; const Touches: TTouches; const Action: TTouchAction);
var
  T:TTouch;
  F: TfmxObject;
  M: TrectF;
  L: TLine;
  R: TRoundRect;
  P: TPoint;
begin
  for T in Touches do begin
    case Action of
      TTouchAction.down,
      TTouchAction.Move:
        for F in Children do
          if F is Tlayout then begin
            M := TLayout(F).AbsoluteRect;
            M.Inflate(0, -10);
            if M.Contains(T.Location) then begin
              L := TLine(TLayout(F).Children[0]);
              R := TRoundRect(L.Children[0]);
              P := TLayout(F).AbsoluteToLocal(T.Location);
              P.X := R.Position.X;
              P.Y := P.Y - 10 - R.Height * 0.5;
              R.Position.Point := P;
            end;
          end;
    end;
  end;
end;

Here is a screenshot:

image

CodePudding user response:

TPoint has Integer fields, and TPointF has Single (floating point) fields.

You need to use one or the other, or convert between Integer/Single.

CodePudding user response:

In P := TLayout(F).AbsoluteToLocal(T.Location);, you are trying to assign a TPointF to a TPoint, but they are completely different types that are not assignment-compatible with each other. TPointF holds Singles whereas TPoint holds Integers instead.

In P.X := R.Position.X;, you are trying to assign a Single to an Integer. That assignment is not allowed without a type-cast.

In P.Y := P.Y - 10 - R.Height * 0.5;, you are trying to assign an Extended to an Integer. That assignment is not allowed without a type-cast.

That said, TLayout.AbsoluteToLocal() returns a TPointF, and R.Position.Point wants a TPointF, so your P variable should be declared as TPointF instead of TPoint. That should solve all 3 of your errors.

  • Related