hi i’m trying to make an editbox move down from 300 by 30 when a button is clicked, and upon clicking the same button again, make editbox move back up by 30 to its original position. However when i click the button ive made it just moves up by 30 each time, where am i going wrong? here is my code,
procedure TfrmProject.Button3Click(Sender: TObject);
begin
if Edit1.Top = 300 then
Edit1.Top := Edit1.Top + 30 else
Edit1.Top := Edit1.Top - 30;
end;
EDIT: I have realised that due to my form being long and having a vertical scrollbar, the property Top of the editbox changes in response to where i am on the form, i.e if i’m at the top of my form the Top property of the edit box increases (the editbox is near the bottom of the form), therefore my new question is how could i ensure the editbox only moves between 2 fixed points, as following the recent suggestions the edit box moves between two points with a 30 distance between them, but their positions on the form change.
This works perfectly fine for me.
Create a new Delphi VCL Forms Application
Drop a TEdit and a TButton on the new form. Set the
Top' property of each to50using theObject Inspector`.Double-click
Button1, and paste the following code to replace the newly generatedTForm1.Button1Clickevent:Run the application. Repeatedly clicking
Button1makesEdit1move up and down from50to80.This means your comparison is wrong. Set the
Button1.Topexplicitly to the original coordinate (300in your code) instead of reducing by30.