Jump to content
Sign in to follow this  
Linuxuser1234

how can i make my slider which is a TRoundrect move without getting Access Violation

Recommended Posts

How can i make a slider that moves from left to right or in vise versa i have tried this youtube tutorial but every time i moved the RoundRect i keep getting 

access violation error  and here is what my slider looks like 945431518_Screenshot2022-10-29113330.png.dac6209f24f88ba9e5bde8100d83649e.png

 

Share this post


Link to post

Did you follow the tutorial exactly? If you provide the code then we'd be able to help a lot more.

Share this post


Link to post

@XylemFlow here is the code 

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
  var
  T:TTouches;
begin
 if ssLeft in Shift
 then begin
   SetLength(T, 1);
   T[0].Location:=PointF(X, Y);
   FormTouch(Nil, T, TTouchAction.Down);
 end;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Single);
 var T:TTouches;
begin
 if ssLeft in Shift
 then begin
   SetLength(T, 1);
   T[0].Location:=PointF(X, Y);
   FormTouch(Nil, T, TTouchAction.Move);
 end;
end;

procedure TForm1.FormTouch(Sender: TObject; const Touches: TTouches;
  const Action: TTouchAction);
  var T:TTouch;
  F: TFmxObject;
  M: TRectF;
  L: TLine;
  R: TRoundRect;
  P: TPointF;
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;

 

Share this post


Link to post

@Sherlock  i commeted each line to see what throws the error all of these lines shows the error under the 2nd 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;

 

Share this post


Link to post

Well, don't typecast without checking if the type fits. You need to check if F really is a TLayout and if child 0 really is a TLine. Something like:

if F is TLayout then
  if TLayout(F).Children[0] is TLine then
    L:=TLine(TLayout(F).Children[0]);

On the other hand you should only type cast when necessary. TFMXObject has a perfectly fine Children property no need to cast F into a TLayout.

 

Check your entire code for these things and you should have eliminated one cause for the AV.

  • Like 1

Share this post


Link to post

I see that F is indeed checked further up. I only considered the last quoted portion of code. As for the "tutorial" it is quite tedious to follow. I personally hate video tutorials, because they are always to slow when it does not matter and to fast when it does. A readable tutorial is worth so much more than that. Anyway... I recreated the project as stated in the video,I even copied your code, and it works without errors. You must have done something different along the line...especially since your screenshot somewhat differs from the video.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×