PROCEDURE relabel;
VAR i: INTEGER;
BEGIN
WITH TCustomTabControl(DisplayForm.Notebook1) DO BEGIN
FOR i:= 1 TO PageCount - 1 DO BEGIN
Pages.Strings[i]:= 'Rule ' + IntToStr(i);
TFrameDisplayFilter(CustomPage(i).Controls[0]).Name:= 'FrameDisplayFilter_' + IntToStr(i);
TFrameDisplayFilter(CustomPage(i).Controls[0]).ButtonDelete.Enabled:= PageCount > 2
END;
(* Note two-phase rename here so that we don't have two components named the *)
(* same when we do an "Insert Before". *)
FOR i:= 1 TO PageCount - 1 DO
TFrameDisplayFilter(CustomPage(i).Controls[0]).Name:= 'FrameDisplayFilter' + IntToStr(i)
END
END { relabel } ;
PROCEDURE insertCommon(insertAt: INTEGER; copyFrom: TTabSheet);
(* Insert the indicated page. Don't try to do anything clever with the catch- *)
(* all state since the act of inserting a page won't risk discarding data. *)
VAR cf, ct: TFrameDisplayFilter;
BEGIN
WITH TCustomTabControl(DisplayForm.Notebook1) DO BEGIN
Pages.Insert(insertAt, 'XX' + IntToStr(insertAt) + 'XX');
Assert(Pages.Objects[insertAt] IS TTabSheet);
TTabSheet(Pages.Objects[insertAt]).InsertControl(TFrameDisplayFilter.Create(DisplayForm), 0)
END;
(* Replicate the current page's settings to the new one. Note that this doesn't *)
(* attempt any Assign() operations since I want to make sure that all objects *)
(* remain distinct. *)
Assert(copyFrom.Controls[0] IS TFrameDisplayFilter);
cf:= TFrameDisplayFilter(copyFrom.Controls[0]);
ct:= TFrameDisplayFilter(DisplayForm.Notebook1.CustomPage(insertAt).Controls[0]);
ct.RadioGroupDirection.ItemIndex:= cf.RadioGroupDirection.ItemIndex;
ct.RadioGroupPause.ItemIndex:= cf.RadioGroupPause.ItemIndex;
ct.RadioGroupRts.ItemIndex:= cf.RadioGroupRts.ItemIndex;
ct.RadioGroupCts.ItemIndex:= cf.RadioGroupCts.ItemIndex;
ct.RadioGroupDsr.ItemIndex:= cf.RadioGroupDsr.ItemIndex;
ct.RadioGroupDtr.ItemIndex:= cf.RadioGroupDtr.ItemIndex;
ct.RadioGroupCd.ItemIndex:= cf.RadioGroupCd.ItemIndex;
ct.RadioGroupRing.ItemIndex:= cf.RadioGroupRing.ItemIndex;
ct.RadioGroupError.ItemIndex:= cf.RadioGroupError.ItemIndex;
ct.CheckGroupErrors.Checked[0]:= cf.CheckGroupErrors.Checked[0];
ct.CheckGroupErrors.Checked[1]:= cf.CheckGroupErrors.Checked[1];
ct.CheckGroupErrors.Checked[2]:= cf.CheckGroupErrors.Checked[2];
ct.RadioGroupCharMatch.ItemIndex:= cf.RadioGroupCharMatch.ItemIndex;
ct.LabeledEditCharMatchMin.Text:= cf.LabeledEditCharMatchMin.Text;
ct.LabeledEditCharMatchMax.Text:= cf.LabeledEditCharMatchMax.Text;
ct.RadioGroupCharMatch2.ItemIndex:= cf.RadioGroupCharMatch2.ItemIndex;
ct.ComboBoxCharset.Text:= cf.ComboBoxCharset.Text;
ct.ColorBoxForeground.Selected:= cf.ColorBoxForeground.Selected;
ct.ColorBoxBackground.Selected:= cf.ColorBoxBackground.Selected;
ct.CheckBoxCatchall.Checked:= cf.CheckBoxCatchall.Checked;
relabel (* ...and rebuild internal structures *)
END { insertCommon } ;