Jump to content
Sign in to follow this  
Linuxuser1234

Access violation error when communicating with a component

Recommended Posts

Im trying to communicate with a component in Unit1 from Unit4  but when i click on the button i get a access violation error how can i resolve this 

 

procedure TForm4.Button1Click(Sender: TObject);
var
Label21: Tlabel;
Button1: Boolean;
ProgressBar1 : TProgressBar;
begin
//
ProgressBar1.Visible := True; //Component is in Unit1 (Bolt)
end;

 

Screenshot 2023-01-06 093210.png

Share this post


Link to post

Nothing shown references a component in another unit. I only see a local ProgressBar1 defined in the Var section of your procedure that isn't created / initialized so will throw access violations when an attempt it made to reference/access it. 

 

Usually you would put the other form unit in the Uses clause of the implementation section of the form you want to reference it from. Then use the form variable to access it like Form1.ProgressBar1.Visible := true;.

 

implementation


{$R *.dfm}

uses Unit1;

 

 

Edited by Brian Evans
  • Like 1

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  

×