unit ControlUnit; interface uses Controls , StdCtrls, ComCtrls, Classes, StringUnitLight; type TSelectDirection = (sdPrev, sdNext); procedure PageControlMoveItem(PageControl: TPageControl; Direction: TSelectDirection; CheckTabVisible: Boolean = True; Rotation: Boolean = False); procedure ListBoxMoveItem(ListBox: TListBox; Direction: TSelectDirection; Rotation: Boolean = False); procedure ListViewMoveItem(ListView: TListView; Direction: TSelectDirection; Rotation: Boolean = False); function CheckIncludeParentControl(Parent: TWinControl; TargetControl: TWinControl): Boolean; procedure ListViewTabInitialize(ListView: TListView; PageControl: TPageControl); procedure ListBoxTabInitialize(ListBox: TListBox; PageControl: TPageControl); procedure CheckBoxNoEventChekckChange(ChkBox: TCheckBox; Value: Boolean); function ListViewToText(ListView: TListView): String; implementation {------------------------------- // PageControl/ListBox/ListViewの 選択を切り替える処理 機能: Direction sdPrev:一つ前を選択 sdNext:次を選択 Rotation True:一番前でsdPrevを選択すると一番後ろに移動 備考: PageControlの場合は CheckTabVisible=Trueでタブ非表示シートを無視する事ができる 履歴: 2007/01/04(木) 18:37 //------------------------------} procedure PageControlMoveItem(PageControl: TPageControl; Direction: TSelectDirection; CheckTabVisible: Boolean = True; Rotation: Boolean = False); var Tab: TTabSheet; begin if PageControl.ActivePageIndex = -1 then Exit; if Rotation then begin case Direction of sdPrev: begin PageControl.SelectNextPage(False, CheckTabVisible); end; sdNext: begin PageControl.SelectNextPage(True, CheckTabVisible); end; end; end else begin case Direction of sdPrev: begin Tab := PageControl.FindNextPage(PageControl.ActivePage, False, CheckTabVisible); {↓Rotationしてしまっているなら} if PageControl.ActivePage.PageIndex <= Tab.PageIndex then Exit; PageControl.SelectNextPage(False); end; sdNext: begin Tab := PageControl.FindNextPage(PageControl.ActivePage, True, CheckTabVisible); {↓Rotationしてしまっているなら} if Tab.PageIndex <= PageControl.ActivePage.PageIndex then Exit; PageControl.SelectNextPage(True); end; end; end; end; procedure ListBoxMoveItem(ListBox: TListBox; Direction: TSelectDirection; Rotation: Boolean = False); begin if ListBox.ItemIndex = -1 then Exit; case Direction of sdPrev: begin if Rotation and (ListBox.ItemIndex <= 0) then begin ListBox.ItemIndex := ListBox.Count - 1; end else if (not Rotation) and (ListBox.ItemIndex <= 0) then begin Exit; end else begin ListBox.ItemIndex := ListBox.ItemIndex - 1; end; end; sdNext: begin if Rotation and (ListBox.Count-1 <= ListBox.ItemIndex) then begin ListBox.ItemIndex := 0; end else if (not Rotation) and (ListBox.Count-1 <= ListBox.ItemIndex) then begin Exit; end else begin ListBox.ItemIndex := ListBox.ItemIndex + 1; end; end; end; end; procedure ListViewMoveItem(ListView: TListView; Direction: TSelectDirection; Rotation: Boolean = False); begin if ListView.ItemIndex = -1 then Exit; case Direction of sdPrev: begin if Rotation and (ListView.ItemIndex <= 0) then begin ListView.ItemIndex := ListView.Items.Count - 1; end else if (not Rotation) and (ListView.ItemIndex <= 0) then begin Exit; end else begin ListView.ItemIndex := ListView.ItemIndex - 1; end; end; sdNext: begin if Rotation and (ListView.Items.Count-1 <= ListView.ItemIndex) then begin ListView.ItemIndex := 0; end else if (not Rotation) and (ListView.Items.Count-1 <= ListView.ItemIndex) then begin Exit; end else begin ListView.ItemIndex := ListView.ItemIndex + 1; end; end; end; end; //------------------------------ {------------------------------- // 親コントロールに含まれるかどうか判断する関数 機能: Button1がTabSheetにのっかっているのか判断する場合 CheckIncludeParentControl(TabSheet1, Button1) として使います 備考: 履歴: 2007/01/04(木) 18:42 //------------------------------} function CheckIncludeParentControl(Parent: TWinControl; TargetControl: TWinControl): Boolean; var WinControl: TWinControl; begin Result := False; WinControl := TargetControl.Parent; while WinControl.Parent <> nil do begin if WinControl = Parent then begin Result := True; Break; end; WinControl := WinControl.Parent; end; end; //------------------------------ {------------------------------- // PageControlのタブをListBox/ListViewで代替するときの 初期化処理 機能: 備考: 履歴: 2007/01/04(木) 18:42 //------------------------------} procedure ListViewTabInitialize(ListView: TListView; PageControl: TPageControl); var i, Index: Integer; ListItem: TListItem; SelectIndex: Integer; begin SelectIndex := PageControl.ActivePageIndex; ListView.Items.Clear; Index := 0; for i := 0 to PageControl.PageCount - 1 do begin {↓Tabが非表示になっているページを最後尾に移動する} if PageControl.Pages[Index].TabVisible = False then begin PageControl.Pages[Index].PageIndex := PageControl.PageCount -1; Continue; end; ListItem := ListView.Items.Add; ListItem.Caption := PageControl.Pages[Index].Caption; PageControl.Pages[Index].TabVisible := False; Inc(Index); end; if (0 <= SelectIndex) and (SelectIndex <= ListView.Items.Count-1) then begin ListView.ItemIndex := SelectIndex; end; end; procedure ListBoxTabInitialize(ListBox: TListBox; PageControl: TPageControl); var i, Index: Integer; ListItem: TListItem; SelectIndex: Integer; begin SelectIndex := PageControl.ActivePageIndex; ListBox.Items.Clear; Index := 0; for i := 0 to PageControl.PageCount - 1 do begin {↓Tabが非表示になっているページを最後尾に移動する} if PageControl.Pages[Index].TabVisible = False then begin PageControl.Pages[Index].PageIndex := PageControl.PageCount -1; Continue; end; ListBox.Items.Add(PageControl.Pages[Index].Caption); PageControl.Pages[Index].TabVisible := False; Inc(Index); end; if (0 <= SelectIndex) and (SelectIndex <= ListBox.Count-1) then begin ListBox.ItemIndex := PageControl.ActivePageIndex; end; end; //------------------------------ {------------------------------- // ユーザー操作 // チェックボックスをイベント発生無しに // Checkプロパティを変化させるコード 備考: 履歴: 2005/08/15 //------------------------------} procedure CheckBoxNoEventChekckChange(ChkBox: TCheckBox; Value: Boolean); var EventBuffer: TNotifyEvent; begin EventBuffer := ChkBox.OnClick; ChkBox.OnClick := nil; ChkBox.Checked := Value; ChkBox.OnClick := EventBuffer; end; //------------------------------ {------------------------------- // ListViewを文字列変換する処理 セルをタブ区切り文字としてコピーする処理 機能: 備考: 履歴: 2007/01/31(水) 14:55 //------------------------------} function ListViewToText(ListView: TListView): String; var ClipText: String; i, j: Integer; begin ClipText := ''; {↓ヘッダ文字列のコピー} for i := 0 to ListView.Columns.Count-1 do begin ClipText := ClipText + ListView.Columns.Items[i].Caption + TAB; end; SetLength(ClipText, Length(ClipText)-1); ClipText := ClipText + sLineBreak; for i := 0 to ListView.Items.Count-1 do begin if not ListView.Items[i].Selected then continue; ClipText := ClipText + ListView.Items[i].Caption + TAB; for j := 0 to ListView.Items[i].SubItems.Count-1 do begin ClipText := ClipText + ListView.Items[i].SubItems[j] + TAB; end; SetLength(ClipText, Length(ClipText)-1); ClipText := ClipText + sLineBreak; end; Result := ClipText; end; //------------------------------ end.