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 9269561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:09:15+00:00 2026-06-18T15:09:15+00:00

I am trying to check if a component is type TMachine or TLabel if

  • 0

I am trying to check if a component is type TMachine or TLabel if so i want it to free it as long as its NOT Label1 or label2

but it will not let me do an OR on if Components[I] is (TMachine) or (TLabel) then Any way to fix this?

    procedure TfDeptLayout.FormClose(Sender: TObject; var Action: TCloseAction);
var
  I: Integer;
begin
     for I := ComponentCount -1 downto 0 do
      begin
          if Components[I] is (TMachine) or (TLabel) then
              if Components[I].Name <> Label2.Name then
                if Components[I].Name <> label3.Name then
                  components[I].Free;
      end;
end;
  • 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-18T15:09:16+00:00Added an answer on June 18, 2026 at 3:09 pm

    You cannot use or in that way, you need to “repeat” the is as well.

    You also don’t need to use Components[I].Name, it suffices to simpy compare the Components[I] reference with the Label1 and Label2 references:

    procedure TfDeptLayout.FormClose(Sender: TObject; var Action: TCloseAction);
    var
      I: Integer;
    begin
         for I := ComponentCount -1 downto 0 do
         begin
           if (Components[I] is TMachine) or (Components[I] is TLabel) then
             if Components[I] <> Label2 then
               if Components[I] <> label3 then
                 components[I].Free;
          end;
    end;
    

    it would also be possible (but maybe less readable) to combine all of the conditionals:

    procedure TfDeptLayout.FormClose(Sender: TObject; var Action: TCloseAction);
    var
      I: Integer;
      comp: TComponent;
    begin
         for I := ComponentCount -1 downto 0 do
         begin
           Comp := Components[I];
           if (Comp is TMachine) then
             Comp.Free
           else if (Comp is TLabel) and (Comp <> Label2) and (Comp <> Label3) then
             Comp.Free;
         end;
    end;
    

    As an aside, it is best to give components that are referred to in code a meaningful name, rather than using the default Label1, Label2… names

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

Sidebar

Related Questions

I'm trying to check network available or not. But in my emulator it always
I am trying to call a JavaScript function from icefaces check box component like
I'm trying to create a sub-class of the JButton component that will enable or
I am trying to implement jQuery with PrimeFaces and JSF components, but it's not
I am trying to use Symfony 2 security component, but I have a problem
I'm trying to figure out how to check if a component is null (e.g.
I'm trying to add a multiple select list to my backend component, but I
I am trying to use the Check Box makes the component greyout/ disable. field.setDisabled(true);
I am trying to check a series of buttons to see if they have
I'm trying to check if a file exists. If I use this: NSData *data

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.