It's entirely possible to have nested with
statements. It's generally not a good idea, since the badness of with
statements compounds, but the compiler has no trouble interpreting the code. When resolving identifiers, the compiler simply works its way from the inner statement to the outer one until it finds an object that has the method or property it's looking for.
What the compiler finds may differ from what you expect it to find.
You can make your code considerably more concise by using some variables and loops to avoid repeating code, as well as to remove the need for a with
statement.
procedure TFGetZoneDept.ComboBox1Select(Sender: TObject);
var
text1, text2: string;
i: Integer;
begin
Combobox2.Clear;
text1 := Combobox1.Text;
if text1 = '3' then
text2 := 'Zone 3 depots'
else if text1 = '4' then
text2 := 'Zone 4 depts'
else if text ='1' then
text2 := 'Zone 1 depts'
else if text ='2' then
text2 := 'Zone 2 depts'
else if text ='BoneYard' then
text2 := 'BoneYard depts'
else if text = 'Misc' then
text2 := 'Misc Depts';
for i := 1 to 6 do
Combobox2.Items.add(text2);
Combobox2.Enabled := true;
end;
When you avoid repeating code, you also avoid mistakes. Unless you meant for all the cases to have six options except zone 4, which only has five.