Mega Code Archive

 
Categories / Delphi / Examples
 

Componentiterate

iterate through components on a form (in this case looking only for TMenuItem components) function TMainForm.IsDuplicateMenuName(name: String): Boolean; //iterate through all existing menu items looking for the name passed in. //If it already exists, then return False. Otherwise return True... var idx: Integer; temp : TComponent; begin Result := True; for idx := 0 to (ComponentCount - 1) do begin temp := Components[idx]; if (temp is TMenuItem) then begin if UpperCase(TMenuItem(Temp).Name) = UpperCase(name) then Result := False; end; end; end; ************************************************************************************ Note: a generalised VISUAL BASIC equivalent of the code in the for loop above will look like this: for each Control in FormName.Controls 'process object next Control [neat...] ************************************************************************************ here we iterate through the pages on a PageControl after all of these pages have been created dynamically /////////////////////////////////////////////////////// procedure TStepPropertiesForm.FormShow(Sender: TObject); var idx: Integer; entityName: String; tab: TTabsheet; ctrlIdx: Integer; containerNo: Integer; begin StepNameEdit.Text := ListsManager.GetStepName(currStepIdx); StepDescripEdit.Text := ListsManager.GetStepDescription(currStepIdx); //note that we will not know how many pages (ie PageControls) the //step properties form should include until after this program has //loaded up and got it's data from the middle tier containerNo := 0; for idx := 2 to (StepPropsPageControl.PageCount - 1) do begin tab := StepPropsPageControl.Pages[idx]; for ctrlIdx := 0 to (tab.ControlCount - 1) do begin if tab.Controls[ctrlIdx] is TImage then begin entityName := ListsManager.GetStepEntityContainerName(currStepIdx, containerNo); DrawObj.GetBitMap(tempBitMap, entityName, entityImageWidth, entityImageHeight); FillTempBitMap(clBtnFace); (tab.Controls[ctrlIdx] as TImage).Picture.Assign(tempBitMap); end; end; Inc(containerNo); end; end;