Linuxuser1234 1 Posted November 8, 2022 I made a RoundRect to look like a tune Knob and i would like the knob to rotate on click so how can i write a Onclick procedure to rotate the round rect at different angles Share this post Link to post
Rollo62 536 Posted November 8, 2022 In FMX you have RotationAngle and RotationCenter, that should be doing it. Share this post Link to post
Linuxuser1234 1 Posted November 8, 2022 (edited) procedure TForm7.KnobClick(Sender: TObject); begin //Knob property RotationAngle: Single read GetRotationAngle write SetRotationAngle; end; @Rollo62 this causes Expected END but received Property Edited November 8, 2022 by Linuxuser1234 Share this post Link to post
Rollo62 536 Posted November 8, 2022 (edited) procedure TForm7.FormCreate(Sender: TObject); begin MyRoundRect.RotationCenter.Point( Pointf( MyRoundRect.Position.X + MyRoundRect.Width / 2.0, MyRoundRect.Position.Y + MyRoundRect.Height / 2.0 ) ); end; procedure TForm7.KnobLeftClick(Sender: TObject); begin MyRoundRect.RotationAngle := MyRoundRect.RotationAngle - 15.0; end; procedure TForm7.KnobRightClick(Sender: TObject); begin MyRoundRect.RotationAngle := MyRoundRect.RotationAngle + 15.0; end; Something similar like this (Untested) ? Or even adding some smooth animation by TFloatAnimation, like this. Edited November 8, 2022 by Rollo62 1 Share this post Link to post
Linuxuser1234 1 Posted November 8, 2022 (edited) @Rollo62 ignore this comment Edited November 8, 2022 by Linuxuser1234 Share this post Link to post
Linuxuser1234 1 Posted November 8, 2022 (edited) @Rollo62 also how would i change a tlabel text based on what angle the knob is set to for example if the angle is at 15deg the tlabel would display another text and i do know how to set the text just not sure how to set the text based off the knob angle Edited November 8, 2022 by Linuxuser1234 Share this post Link to post
Rollo62 536 Posted November 8, 2022 (edited) function TForm7.GetMyStationNameFromAngleMethod( const AAngle : Single ) : String; const CStations : array[0..24-1] of String = ( 'New York, 'Honolulu', 'Tokyo' ... 'Paris' ); var LIdx : Integer; begin LIdx := AAngle div 15.0; // 0 ... 360 to 0 ... 23 Result := CStations[ LIdx ]; end; function TForm7.GetMyStationFreqFromAngleMethod( const AAngle : Single ) : Single; begin Result := (AAngle / 360.0) * 200.0; // 0 ... 360 to 0 ... 200.0 MHz end; procedure TForm7.KnobLeftClick(Sender: TObject); begin MyRoundRect.RotationAngle := MyRoundRect.RotationAngle - 15.0; Label1.Text := Format( 'My station is %s at %4.0f MHz, [ GetMyStationNameFromAngleMethod( MyRoundRect.RotationAngle ), GetMyStationFreqFromAngleMethod( MyRoundRect.RotationAngle ) ] ); end; procedure TForm7.KnobRightClick(Sender: TObject); begin MyRoundRect.RotationAngle := MyRoundRect.RotationAngle + 15.0; Label1.Text := Format( 'My station is %s at %4.0f MHz, [ GetMyStationNameFromAngleMethod( MyRoundRect.RotationAngle ), GetMyStationFreqFromAngleMethod( MyRoundRect.RotationAngle ) ] ); end; I assume you want to display the station name and frequency, right ? Just a rough idea, its already very late here ... Since I don't know exactly what you need this is a wild guess 🙂 Edited November 8, 2022 by Rollo62 1 Share this post Link to post
Linuxuser1234 1 Posted November 9, 2022 @Rollo62 sorry if this question sounds basic but i cant figure out how to fix this error TForm7 does not contain a member named KnobLabelStationAngle i have put the function line under the procedure and in public/private nothing worked Share this post Link to post
Rollo62 536 Posted November 9, 2022 (edited) You can simply add your function declaration and definition in the code window, similar like this: unit UMain_Form; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts ; type TForm1 = class(TForm) private { Private declarations } public { Public declarations } function MakeANewFunction( const AParam : Single ) : String; end; var Form1: TForm1; implementation {$R *.fmx} { TForm1 } function TForm1.MakeANewFunction(const AParam: Single): String; begin if AParam > 100.0 then Result := 'Large' else if AParam >= 0.0 then Result := 'Small' else Result := 'Negative'; end; end. For these kind of questions you better look into a good, basic Delphi book, like this one from Marco Cantu. Edited November 9, 2022 by Rollo62 Share this post Link to post
Linuxuser1234 1 Posted November 9, 2022 (edited) @Rollo62 i put the function under public still wont work private { Private declarations } public { Public declarations } function TForm7.KnobLabelStationAngle(const AAngle : Single) : String; overload; function TForm7.KnobLabelFreqAngle(const AAngle : Single ) : Single; overload; end; procedure TForm7.KnobClick(Sender: TObject); begin //Knob Knob.RotationAngle := Knob.RotationAngle - 15.0; Rectangle4.RotationAngle := Knob.RotationAngle - 15.0; Label2.Text := Format ('%s', [KnobLabelStationAngle(Knob.RotationAngle), KnobLabelFreqAngle(Knob.RotationAngle) ] ); end; function TForm7.KnobLabelStationAngle(const AAngle : Single) : String; const CStationLabel : array[0..24-1] of String = ('KEC61', 'WXK30'); var LIdx : Integer; begin LIdx := AAngle div 15.0; Result := CStationLabel[LIdx]; end; function TForm7.KnobLabelFreqAngle(const AAngle : Single ) : Single; begin Result := (AAngle / 162.550 * 162.525 * 162.500 * 162.400 * 162.475) end; Edited November 9, 2022 by Linuxuser1234 Share this post Link to post
Rollo62 536 Posted November 9, 2022 What I spot without too much looking into details: Your inside TForm7 declaration, so don't write TForm7. here private { Private declarations } public { Public declarations } //function TForm7.KnobLabelStationAngle(const AAngle : Single) : String; overload; function KnobLabelStationAngle(const AAngle : Single) : String; overload; //function TForm7.KnobLabelFreqAngle(const AAngle : Single ) : Single; overload; function KnobLabelFreqAngle(const AAngle : Single ) : Single; overload; end; Share this post Link to post
Linuxuser1234 1 Posted November 9, 2022 (edited) @Rollo62 now i get this and also when i click on the design tab i keep getting a error saying container form not set and i changed the name from ignore the first error i got it fixed but im still getting the second error //second error line LIdx := AAngle div 15.0; Edited November 9, 2022 by Linuxuser1234 Share this post Link to post
Linuxuser1234 1 Posted November 9, 2022 (edited) @Rollo62 i just had to restart the ide to get rid of the container form not set message Edited November 9, 2022 by Linuxuser1234 Share this post Link to post
Rollo62 536 Posted November 9, 2022 (edited) Ok, ok, here is a short demo maybe what you are looking for, additionally with some mouse drag-and-drop for the knob.. I would really recommend that you look into some books and the help before continuing, as well as checking out all the samples. Maybe that small demo helps for a start, but you should begin with the basics first. T465_Rotation_001.zip Edited November 9, 2022 by Rollo62 Share this post Link to post