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;
You cannot use
orin that way, you need to “repeat” theisas 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:
it would also be possible (but maybe less readable) to combine all of the conditionals:
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