Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9267441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:33:02+00:00 2026-06-18T14:33:02+00:00

First, I was haveing combobox1 fill combobox2 during the onselect. I started the long

  • 0

First, I was haveing combobox1 fill combobox2 during the onselect. I started the long way see below.

    procedure TFGetZoneDept.ComboBox1Select(Sender: TObject);
begin
  Combobox2.Clear;
  with Combobox1 do
  begin
      if text = '3' then
      begin
        with combobox2 do
        begin
          Add('Zone 3 depts');
          Add('Zone 3 depts');
          Add('Zone 3 depts');
          Add('Zone 3 depts');
          Add('Zone 3 depts');
          Add('Zone 3 depts');
        end;   {with combobox2}
      end;  {If }
      if text = '4' then
      begin
        with ComboBox2 do
        begin
          add('Zone 4 depts');
          add('Zone 4 depts');
          add('Zone 4 depts');
          add('Zone 4 depts');
          add('Zone 4 depts)';
        end;{combobox2 with}
      end;{IF}
      if text ='1' then
      begin
        with ComboBox2 do
        begin
          add('Zone 1 depts');
          add('Zone 1 depts');
          add('Zone 1 depts');
          add('Zone 1 depts');
          add('Zone 1 depts');
          add('Zone 1 depts');
        end; {combobox2 with}
      end; {IF}
      if text ='2' then
      begin
        with ComboBox2 do
        begin
          add('Zone 2 depts');
          add('Zone 2 depts');
          add('Zone 2 depts');
          add('Zone 2 depts');
          add('Zone 2 depts');
          add('Zone 2 depts');
        end; {Combobox2 with}
      end; {IF}
      if text ='BoneYard' then
      begin
        with ComboBox2 do
        begin
          add('BoneYard depts');
          add('BoneYard depts');
          add('BoneYard depts');
          add('BoneYard depts');
          add('BoneYard depts');
          add('BoneYard depts');
        end; {combobox2 with}
      end; {IF}
      if text = 'Misc' then
      begin
        with ComboBox2 do
          begin
            add('Misc Depts');
            add('Misc Depts');
            add('Misc Depts');
            add('Misc Depts');
            add('Misc Depts');
            add('Misc Depts');
          end; {combobox2 with}
      end; {IF}
  end;{combobox1 with}
  Combobox2.Enabled := true;
end;

I noticed you cant use one with with another with inside.. or am i doing it wrong. Second I started to think there has to be a better way 😀 So either answer is ok. Either how to fix the with or do this a better way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:33:03+00:00Added an answer on June 18, 2026 at 2:33 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble with the procedure below. First pass through the procedure, everything
Is there a way to write a String directly to S3, without first having
In my html table I have two row, first row having no css but
I'm having my first play around with Ember.js, and am falling at the first
What I want is to have a table having a first column with every
I am using MVC-View Model, EF Model first I am having problems with two
First of all I am having trouble with the concept of a mathematical Vector
First time cake user and I'm having real apache problems. For some reason the
I am taking my first steps in C++ having a good background in Java.
I am having an issue where only the text of the first TextView (eventItemTitle)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.