⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xcontrols.pas

📁 《Delphi深度历险》附书源码 Delphi学习书本
💻 PAS
字号:
unit xControls;

interface

uses Windows, Messages, SysUtils, Forms, Classes, Controls, ComCtrls;

procedure EnableControl(AControl: TControl; Enable: Boolean);
procedure EnableChildControls(AControl: TControl; Enable: Boolean);
procedure EnableClassControl(AControl: TControl; Enable: Boolean; ControlClass: TControlClass);

procedure SelectPageIndex(const PC: TPageControl; const iIndex: Integer; const Animated: Boolean);
procedure MakeSureTabVisible(const PC: TPageControl);

procedure LoadTreeViewFromTextFile(Nodes: TTreeNodes; Filename: string);
procedure SaveTreeViewToTextFile(Nodes: TTreeNodes; Filename: string);

implementation

uses xStrings;


procedure EnableControl(AControl: TControl; Enable: Boolean);
var
  I: Integer;
begin
  AControl.Enabled := Enable;
  if AControl is TWinControl then
    with TWinControl(AControl) do
    begin
      for I := 0 to ControlCount - 1 do
        EnableControl(Controls[I], Enable);
    end;
end;

procedure EnableChildControls(AControl: TControl; Enable: Boolean);
var
  I: Integer;
begin
  if AControl is TWinControl then
    with TWinControl(AControl) do
    begin
      for I := 0 to ControlCount - 1 do
        EnableControl(Controls[I], Enable);
    end;
end;

procedure EnableClassControl(AControl: TControl; Enable: Boolean; ControlClass: TControlClass);
var
  I: Integer;
begin
  if (AControl is ControlClass) then AControl.Enabled := Enable;
  
  if AControl is TWinControl then
    with TWinControl(AControl) do
    begin
      for I := 0 to ControlCount - 1 do
        EnableClassControl(Controls[I], Enable, ControlClass);
    end;
end;

procedure SelectPageIndex(const PC: TPageControl; const iIndex: Integer; const Animated: Boolean);
var
  oIndex, I: Integer;
begin
  with PC do
  begin
    oIndex := ActivePage.pageindex;
    if Animated then
    begin
      while (ActivePage.pageindex <> iIndex) do
      begin
        SelectNextPage(iIndex > oIndex);
        if ActivePage.pageindex = oIndex then Break;
      end;
      // if not ActivePage.TabVisible then ActivePage := Pages[oIndex];
    end
    else
    begin
      for I := 0 to PageCount - 1 do
        if Pages[I].pageindex = iIndex then
        begin
          if Pages[I].TabVisible then ActivePage := Pages[I] else ActivePage := Pages[oIndex];
          Exit;
        end;
    end;
  end;
end;

procedure MakeSureTabVisible(const PC: TPageControl);
begin
  while not PC.ActivePage.TabVisible do PC.SelectNextPage(True);
end;

procedure LoadTreeViewFromTextFile(Nodes: TTreeNodes; Filename: string);
var
  F: TextFile;
  
  function ProcessNode(Node: TTreeNode; LevelNo: Integer): TTreeNode;
  var
    S : string; 
    No: Integer;
  begin
    Result := Node;
    repeat
      readln(F, S);
      No := ParseRPLNo(S);
      if No > LevelNo then // 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -