I have this simple example of syncing Scrollboxes, where I control which side is synced by Radio button - Sync Left or Right side. When I compile, I get compiler messages:
[dcc32 Warning] Unit1.pas(51): W1036 Variable 'ScrlBox1' might not have been initialized
[dcc32 Warning] Unit1.pas(51): W1036 Variable 'ScrlBox2' might not have been initialized
This is the simple example:
procedure TForm1.Button1Click(Sender: TObject);
var
ScrlBox1, ScrlBox2: TScrollBox;
begin
if radiobtn_SyncLeftSides.Checked then // Snyc Left side
begin
ScrlBox1 := ScrollBoxLeft1;
ScrlBox2 := ScrollBoxLeft2;
end
else if radiobtn_SyncrightSides.Checked then // Snyc Right side
begin
ScrlBox2 := ScrollBoxRight1;
ScrlBox1 := ScrollBoxRight2;
end;
// Sync scroll boxes
ScrlBox2.VertScrollBar.Position := ScrlBox1.VertScrollBar.Position;
ScrlBox2.HorzScrollBar.Position := ScrlBox1.HorzScrollBar.Position;
end;
What is the issue here?
If I add this at the beginning the message is gone:
ScrlBox1:= TScrollBox.Create(nil);
ScrlBox2:= TScrollBox.Create(nil);
but I don't think creating scroll box variables is necessary, right? These are just variable pointers to controls on form.
If both
radiobtn_SyncLeftSides
andradiobtn_SyncrightSides
are unchecked, you are not initializing theScrlBox1
andScrlBox2
variables before using them. That is what the compiler is complaining about.If you don't want to sync the scrolling, you should just
Exit
the procedure: