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

📄 propstorageediteh.pas

📁 最新的 DBGRIDEH4.0
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{$IFDEF EH_LIB_CLX} // Clx BUG of InsertObject
              N := TreeView2.Items.Insert(N.Item[j], TTreeNode(NList[i]).Text);
              N.Data := NList[i];
{$ELSE}
              N := TreeView2.Items.InsertObject(N.Item[j], TTreeNode(NList[i]).Text, NList[i]);
{$ENDIF}
              PropertyAdded(N);
              Abort;
            end;
          N := TreeView2.Items.AddChildObject(N, TTreeNode(NList[i]).Text, NList[i]);
          PropertyAdded(N);
        except
         on EAbort do
         else raise;
        end;
      end;
    end;
    NList.Free;
  end;
  if N <> nil then
    N.Selected := True;
end;

procedure TPropStorageEditEhForm.AddParentChecked(N: TTreeNode);
begin
  N := N.Parent;
  while (N <> nil) and (TNodeInfoEh(N.Data).NodeType = nthProperty) do
  begin
    N.ImageIndex := 2;
    N.SelectedIndex := 2;
    TNodeInfoEh(N.Data).Checked := 2;
    N := N.Parent;
  end;
end;

procedure TPropStorageEditEhForm.ResetParentNodes(N: TTreeNode);
begin
  N := N.Parent;
  if N = nil then Exit;
  if not HaveCheckedChilds(N) then
    RemovePropertyNode(N);
  if (TNodeInfoEh(N.Data).NodeType = nthProperty) then
    if HaveCheckedChilds(N) then
    begin
      N.ImageIndex := 2;
      N.SelectedIndex := 2;
      TNodeInfoEh(N.Data).Checked := 2;
    end else
    begin
      N.ImageIndex := 0;
      N.SelectedIndex := 0;
      TNodeInfoEh(N.Data).Checked := 0;
      RemovePropertyNode(N);
    end;
  ResetParentNodes(N);
end;

procedure TPropStorageEditEhForm.ResetChildNodes(N: TTreeNode);
var
  i: Integer;
begin
  if TNodeInfoEh(N.Data).Checked <> 0 then
    for i := 0 to N.Count-1 do
    begin
      ResetChildNodes(N.Item[i]);
      if TNodeInfoEh(N.Item[i].Data).Checked <> 0 then
      begin
        N.Item[i].ImageIndex := 0;
        N.Item[i].SelectedIndex := 0;
        TNodeInfoEh(N.Item[i].Data).Checked := 0;
        RemovePropertyNode(N.Item[i]);
      end;
    end;
end;

procedure TPropStorageEditEhForm.RemovePropertyNode(N: TTreeNode);
var
  PN: TTreeNode;
  i: Integer;
begin
  PN := N.Parent;
  if Assigned(N) then
    for i := 0 to TreeView2.Items.Count-1 do
      if TreeView2.Items[i].Data = N then
      begin
        PropertyDeleting(TreeView2.Items[i]);
        TreeView2.Items[i].Delete;
        Break;
      end;
  while (PN <> nil) and (PN.Count = 0) do
  begin
    N := PN;
    PN := PN.Parent;
    if N.GetPrevChild(N) <> nil then
      TreeView2.Selected := N.GetPrevChild(N)
    else if N.GetNextChild(N) <> nil then
      TreeView2.Selected := N.GetNextChild(N)
    else
      TreeView2.Selected := N.Parent;
    for i := 0 to TreeView2.Items.Count-1 do
      if TreeView2.Items[i].Data = N then
      begin
        PropertyDeleting(TreeView2.Items[i]);
        TreeView2.Items[i].Delete;
        Break;
      end;
  end;
end;

function TPropStorageEditEhForm.FindChildNodeInfo(N2: TTreeNode; N1: TTreeNode): TTreeNode;
var
  i: Integer;
begin
  Result := nil;
  for i := 0 to N2.Count-1 do
    if (TTreeNode(N2.Item[i].Data).Data) = N1.Data then
    begin
      Result := N2.Item[i];
      Exit;
    end;
end;

function TPropStorageEditEhForm.HaveCheckedChilds(N: TTreeNode): Boolean;
var
  i: Integer;
begin
  Result := False;
  for i := 0 to N.Count-1 do
    if (TNodeInfoEh(N.Item[i].Data).NodeType = nthProperty) then
    begin
      if TNodeInfoEh(N.Item[i].Data).Checked <> 0 then
      begin
        Result := True;
        Exit;
      end;
    end else if (TNodeInfoEh(N.Item[i].Data).NodeType = nthPropNode) then
    begin
      Result := HaveCheckedChilds(N.Item[i]);
      if Result then Exit;
    end else if TNodeInfoEh(N.Item[i].Data).Instance <> nil then
    begin
      if HaveCheckedChilds(N.Item[i]) then
      begin
        Result := True;
        Exit;
      end;
    end;
end;

function TPropStorageEditEhForm.AddSortedChildObject(Parent: TTreeNode;
  const S: string; Data: TNodeInfoEh): TTreeNode;
var
  Node: TTreeNode;
begin
  if Parent = nil
    then Node := TreeView1.Items.GetFirstNode
    else Node := Parent.getFirstChild;
  if Node = nil then
  begin
    Result := TreeView1.Items.AddChildObject(Parent, S, Data);
    Exit;
  end;
  while Node <> nil do
  begin
    if CompareNodeData(TNodeInfoEh(Node.Data), Data) > 0 then
    begin
{$IFDEF EH_LIB_CLX} // Clx BUG of InsertObject
      Result := TreeView1.Items.Insert(Node, S);
      Result.Data := Data;
{$ELSE}
      Result := TreeView1.Items.InsertObject(Node, S, Data);
{$ENDIF}
      Exit;
    end;
    Node := Node.GetNextSibling;
  end;
  Result := TreeView1.Items.AddChildObject(Parent, S, Data);
end;

function TPropStorageEditEhForm.CompareNodeData(Data1, Data2: TNodeInfoEh): Integer;
begin
  if Data1.NodeType = Data2.NodeType then
    if Data1.NodeType = nthProperty then
      if (Copy(Data1.Name, 1, 1) = '<') and
         (Copy(Data2.Name, 1, 1) <> '<')
      then
        Result := 1
      else if (Copy(Data2.Name, 1, 1) = '<') and
              (Copy(Data1.Name, 1, 1) <> '<')
      then
        Result := -1
      else
        Result := CompareText(Data1.Name, Data2.Name)
    else
      Result := CompareText(Data1.Name, Data2.Name)
  else if Data1.NodeType = nthProperty then
    Result := -1
  else if Data1.NodeType = nthPropNode then
    Result := -1
  else
    Result := 1;
end;

function TPropStorageEditEhForm.CompareNode(Node1, Node2: TTreeNode): Integer;
begin
  Result := CompareNodeData(TNodeInfoEh(Node1.Data), TNodeInfoEh(Node2.Data));
end;

procedure TPropStorageEditEhForm.ExchangeNode(Parent: TTreeNode; L, R: Integer);
var
  N: TTreeNode;
begin
  N := TTreeNode.Create(nil);
  N.Assign(Parent.Item[L]);
  Parent.Item[L] := Parent.Item[R];
  Parent.Item[R] := N;
  N.Free;
end;

procedure TPropStorageEditEhForm.QuickSort(Parent: TTreeNode; L, R: Integer);
var
  I, J, P: Integer;
begin
  repeat
    I := L;
    J := R;
    P := (L + R) shr 1;
    repeat
      while CompareNode(Parent.Item[I], Parent.Item[P]) < 0 do Inc(I);
      while CompareNode(Parent.Item[J], Parent.Item[P]) > 0 do Dec(J);
      if I <= J then
      begin
        ExchangeNode(Parent, I, J);
        if P = I then
          P := J
        else if P = J then
          P := I;
        Inc(I);
        Dec(J);
      end;
    until I > J;
    if L < J then QuickSort(Parent, L, J);
    L := I;
  until I >= R;
end;

procedure TPropStorageEditEhForm.BuildPropertyList;
var
  N: TTreeNode;
  ChildList: TStringList;
begin
  TreeView1.Items.BeginUpdate;
  TreeView1.Items.Clear;
  ChildList := nil;
  try
    N := TreeView1.Items.Add(nil, '<Form>: ' + PropStorage.Owner.ClassName);
    N.ImageIndex := 8;
    N.SelectedIndex := 8;
    N.Data := CreateNodeInfo(PropStorage.Owner, '<Form>', '', nthControl, False);
    RootNode := N;
    AddVoidProperty(N);
    N.Expanded := True;
(*
    ChildList := TStringList.Create;
    GetChildList(PropStorage.Owner, PropStorage.Owner, ChildList);
    for i := 0 to ChildList.Count - 1{PropStorage.Owner.ComponentCount - 1} do
    begin
      C := TComponent(ChildList.Objects[i]); //PropStorage.Owner.Components[I];
      if C.Name = '' then Continue;
      N := AddSortedChildObject(nil, C.Name + ': ' + C.ClassName,
        CreateNodeInfo(C, C.Name, C.Name, nthControl, False));
      //N := TreeView1.Items.AddObject(nil, C.Name + ': ' + C.ClassName, Pointer(0));
      //N.Data := CreateNodeInfo(C, C.Name, C.Name, False, False);
      if C is TWinControl
        then N.ImageIndex := 9
        else N.ImageIndex := 10;
      N.SelectedIndex := N.ImageIndex;
      AddVoidProperty(N);

{$IFDEF EH_LIB_5}
      if csInline in C.ComponentState then
      begin
        N.ImageIndex := 11;
        N.SelectedIndex := 11;
//        AddComponents(N, C, C.Name);
      end;
{$ENDIF}

    end;
*)
  finally
    TreeView1.Items.EndUpdate;
    ChildList.Free;
  end;

end;

procedure TPropStorageEditEhForm.BuildStoringPropertyList(PropList: TStrings);
var
  i: Integer;
begin
  for i := 0 to PropList.Count-1 do
    MainAddPropertyNode(PropList[i]);
//  TreeView1.AlphaSort;
  TreeView2.FullExpand;
end;

function TPropStorageEditEhForm.CreateNodeInfo(Component: TComponent; Name, Path: String;
  NodeType: TNodeTypeEh; IsVoidProperty: Boolean): TNodeInfoEh;
var
  PNi: TNodeInfoEh;
begin
//  New(PNi);
  PNi := TNodeInfoEh.Create;
  PNi.Instance := Component;
  PNi.Name := Name;
  PNi.Path := Path;
  PNi.NodeType := NodeType;
  PNi.IsVoidProperty :=  IsVoidProperty;
  PNi.Checked := 0;
  Result := PNi;
end;

procedure TPropStorageEditEhForm.AddVoidProperty(N: TTreeNode);
var
  NC: TTreeNode;
begin
  NC := TreeView1.Items.AddChildObjectFirst(N, 'VoidProperty', nil);
  NC.Data := CreateNodeInfo(nil, 'VoidProperty', 'VoidProperty', nthProperty, True);
end;

function TPropStorageEditEhForm.GetObjectPropList(AObject: TObject; var ObjPropCount: Integer): TPropListArray;//PPropList;
var
  InterClass: TReadPropertyInterceptorClass;
//  PropList, InterPropList, ObjPropList: PPropList;
  PropList, InterPropList, ObjPropList: TPropListArray;
  PropCount, InterPropCount, {FInterSize, FSize,} i, j, Comp: Integer;
  List: TList;
begin
{  PropCount := GetPropList(AObject.ClassInfo, tkProperties, nil);
  FSize := PropCount * SizeOf(Pointer);
  GetMem(PropList, FSize);
  GetPropList(AObject.ClassInfo, tkProperties, PropList);}
  Result := nil;
  InterPropList := nil;
  PropList := GetPropListAsArray(AObject.ClassInfo, tkProperties);
  PropCount := Length(PropList);
  ObjPropCount := PropCount;
  Result := PropList;

  InterClass := GetInterceptorForTarget(AObject.ClassType);
  if InterClass = nil then Exit;

{  InterPropCount := GetPropList(InterClass.ClassInfo, tkProperties, nil);
  FInterSize := InterPropCount * SizeOf(Pointer);
  GetMem(InterPropList, FInterSize);
  GetPropList(InterClass.ClassInfo, tkProperties, InterPropList);}
  InterPropList := GetPropListAsArray(InterClass.ClassInfo, tkProperties);
  InterPropCount := Length(InterPropList);

  List := TList.Create;
  j := 0;
  for i := 0 to PropCount-1 do
  begin
    if j < InterPropCount then
    begin
      Comp := CompareText(PropList[i].Name, InterPropList[j].Name);
      if Comp = 0 then
      begin
        Inc(j);
        List.Add(PropList[i]);
      end else if Comp < 0 then
        List.Add(PropList[i])
      else //Comp > 0
      begin
        List.Add(InterPropList[j]);
        Inc(j);
      end
    end else
      List.Add(PropList[i]);
  end;

  for i := j to InterPropCount-1 do
  begin
    List.Add(InterPropList[i]);
  end;

//  GetMem(ObjPropList, List.Count * SizeOf(Pointer));
  SetLength(ObjPropList, List.Count);
  for i := 0 to List.Count - 1 do
    ObjPropList[i] := PPropInfo(List[i]);

  ObjPropCount := List.Count;
  Result := ObjPropList;

  List.Free;
//  FreeMem(PropList, FSize);
//  FreeMem(InterPropList, FInterSize);
end;

procedure TPropStorageEditEhForm.AddProperties(N: TTreeNode; O: TObject;
  Path: String; IsAddPropNode: Boolean);
var
//  PropList: PPropList;
  PropList: TPropListArray;
  PropCount: Integer;
  i, j: Integer;
  NC: TTreeNode;
  SubO: TObject;
  DefinePropList: TStringList;
begin
  PropList := GetObjectPropList(O, PropCount);
  if Path <> '' then Path := Path + '.';
  if IsAddPropNode then
  begin
    Path := Path + '<P>';
    N := AddSortedChildObject(N, '<Properties>',
        CreateNodeInfo(nil, '<P>', Path, nthPropNode, False));
    N.ImageIndex := 12;
    N.SelectedIndex := 12;
    Path := Path + '.';
  end;
  for i := 0 to PropCount - 1 do
  begin
    NC := AddSortedChildObject(N, PropList[i].Name {+ ': ' + PropList^[i].PropType^.Name},
      CreateNodeInfo(nil, PropList[i].Name, Path + PropList[i].Name, nthProperty, False));
    NC.ImageIndex := 0;
    NC.SelectedIndex := 0;
{$IFDEF CIL}
    if PropList[i].PropType.Kind = tkClass then
{$ELSE}
    if PropList[i].PropType^.Kind = tkClass then
{$ENDIF}
    begin
      SubO := GetObjectProp(O, PropList[i]);
      if Assigned(SubO) then
      begin
        TNodeInfoEh(NC.Data).Instance := SubO;
        if not (SubO is TComponent)
{$IFDEF EH_LIB_6}
          or ((SubO is TComponent) and (csSubComponent in TComponent(SubO).ComponentStyle))
{$ENDIF}
        then
          AddVoidProperty(NC);
      end;
    end;
{$IFNDEF EH_LIB_CLX}
    if (GetTickCount - StartBuildTicks) > 250 then
      Screen.Cursor := crHourGlass;
{$ENDIF}
  end;

  if O is TPersistent then
  begin
    DefinePropList := TStringList.Create;
    GetDefinePropertyList(TPersistent(O), DefinePropList);
    for j := 0 to DefinePropList.Count - 1 do
      if GetChildNodeByText(N, DefinePropList[j]) = nil then
      begin
        NC := AddSortedChildObject(N, DefinePropList[j],
          CreateNodeInfo(nil, DefinePropList[j], Path + DefinePropList[j], nthProperty, False));
        NC.ImageIndex := 0;
        NC.SelectedIndex := 0;
      end;
    DefinePropList.Free;
  end;

  if (O is TCollection) then
    AddCollectionProperties(N, TCollection(O), Path);

//  FreeMem(PropList, PropCount * SizeOf(Pointer));
end;

procedure TPropStorageEditEhForm.AddComponents(N: TTreeNode; O: TComponent; Path: String);
var
  i: Integer;
  C: TComponent;
  NC: TTreeNode;
  ChildList: TStringList;
begin
  if Path <> '' then Path := Path + '.';
  ChildList := TStringList.Create;
  GetComponentChildListEh(O, PropStorage.Owner, ChildList, True);
  for i := 0 to ChildList.Count - 1 do
  begin
    C := TComponent(ChildList.Objects[i]);
    if C.Name = '' then Continue;
    NC := AddSortedChildObject(N, C.Name + ': ' + C.ClassName,
      CreateNodeInfo(C, C.Name, Path + C.Name, nthControl, False));
    if C is TWinControl
      then NC.ImageIndex := 9
      else NC.ImageIndex := 10;
    NC.SelectedIndex := NC.ImageIndex;
    AddVoidProperty(NC);
{$IFDEF EH_LIB_5}
    if csInline in C.ComponentState then
    begin
      NC.ImageIndex := 11;
      NC.SelectedIndex := 11;
    end;

⌨️ 快捷键说明

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