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

📄 jvregautoeditorform.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
            MyNode := Tree.Items.AddChild(Node, AName + ' : '
              + TypeData^.ClassType.ClassName + #0 + 'N');
            MyNode.ImageIndex := imClass; // Picture - Possible to select [translated]
            AComponent := TComponent(GetOrdProp(AComponent, APropInfo));

            { Protection against recursive references of components [translated] }
            if (AComponent = nil) or (CompList.IndexOf(AComponent) > -1) then
              Exit;
            CompList.Add(AComponent);

            aNumProps := TypeData^.PropCount;
            GetMem(aPropList, aNumProps * SizeOf(Pointer));
            try
              GetPropInfos(ATypeInfo, aPropList);
              for I := 0 to aNumProps - 1 do
              begin
                AName := aPropList^[I]^.Name;
                AddToTree(AComponent, aPropList^[I], MyNode);
              end;
            finally
              FreeMem(aPropList, aNumProps * SizeOf(Pointer));
            end;
          end;
        // tkSet    // - Not yet supported [translated]
      end;
    if MyNode <> nil then
      MyNode.SelectedIndex := MyNode.ImageIndex;
  end;

  procedure LoadBitmap;
  var
    Pic, PicTmp: TBitmap;
    s: string;
  begin
    if not (csDesigning in ComponentState) then
      Exit;
    Pic := TBitmap.Create;
    s := Comp.ClassName;
    try
      Pic.LoadFromResourceName(hInstance, UpperCase(pchar(s)));
    except
    end;
    if (Pic.Height <> 24) or (Pic.Width <> 24) then
    begin
      PicTmp := TBitmap.Create;
      PicTmp.Height := 24;
      PicTmp.Width := 24;
      PicTmp.Canvas.Draw(0, 0, Pic);
      Pic.Free;
      Pic := PicTmp;
    end;
    TreeImages.AddMasked(Pic, clOlive);
    Pic.Free;
  end;

begin
  CompList := TList.Create;
  Tree.Items.BeginUpdate;
  try
    Tree.Items.Clear;
    LoadProgress.ProgressBar.Max := Component.Owner.ComponentCount + 2;
    for J := -1 to Component.Owner.ComponentCount - 1 do
    begin
      if J = -1 then
        Comp := Component.Owner
      else
        Comp := Component.Owner.Components[J];

      LoadProgress.ProgressBar.Position := J + 1;
      Application.ProcessMessages;
      if LoadProgress.Canceled then
        Exit;
      //ODS('Read ' + Comp.Name + ':' + Comp.ClassName);

      LoadBitmap;
      ANode := Tree.Items.Add(nil, Comp.Name + ' : ' + Comp.ClassName);
      //    else ANode := Tree.Items.Add(nil, Component.Owner.Components[J].Name +' : '+ Component.Owner.Components[J].ClassName);
      ANode.ImageIndex := imComponent + J + 1;
      ANode.SelectedIndex := ANode.ImageIndex;
      try
        TypeInf := Comp.ClassInfo;
        AName := TypeInf^.Name;
        TypeData := GetTypeData(TypeInf);
        NumProps := TypeData^.PropCount;
        GetMem(PropList, NumProps * SizeOf(Pointer));
        try
          GetPropInfos(TypeInf, PropList);
          for I := 0 to NumProps - 1 do
          begin
            AName := PropList^[I]^.Name;
            CompList.Clear;
            CompList.Add(Comp);
            AddToTree(Comp, PropList^[I], ANode);
          end;
        finally
          FreeMem(PropList, NumProps * SizeOf(Pointer));
        end;
      except
        on E: Exception do
        begin
          E.Message := 'JvRegAutoEditorForm error:' + E.Message;
          raise;
        end;
      end;
    end;
    //  Tree.AlphaSort;
  finally
    CompList.Free;
    Tree.Items.EndUpdate;
  end;
end;

procedure TJvRegEditor.FormResize(Sender: TObject);
begin
  edtProp.Width := panelButtons.Left - edtProp.Left * 2 - 2;
end;

procedure TJvRegEditor.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo);
begin
  inherited;
  Msg.MinMaxInfo^.ptMinTrackSize.X := panelOKCancelApply.Width + 15;
  Msg.MinMaxInfo^.ptMinTrackSize.Y := 200;
end;

procedure TJvRegEditor.TreeChange(Sender: TObject; Node: TTreeNode);
var
  Text, Text1: string;
  P: Integer;
begin
  if Node = nil then
    Exit;
  Text := Node.Text;
  btnAddProp.Enabled := IsEnabled(Text);
  P := Pos(' ', Text);
  if P > 0 then
    Text := System.Copy(Text, 1, P - 1);
  Node := Node.Parent;
  while Node <> nil do
  begin
    Text1 := Node.Text;
    P := Pos(' ', Text1);
    if P > 0 then
      Text1 := System.Copy(Text1, 1, P - 1);
    Text := Text1 + '.' + Text;
    Node := Node.Parent;
  end;
  edtProp.Text := Text;
  {  Ind := List.Items.IndexOf(edtProp.Text);
    if Ind <> -1 then List.ItemIndex := Ind;}
end;

procedure TJvRegEditor.btnAddPropClick(Sender: TObject);
var
  Ind: Integer;
begin
  Ind := List.Items.IndexOf(edtProp.Text);
  if Ind = -1 then
    PropAdd
  else
  if ActiveControl = List then
    PropDelete
  else
  begin
    List.Items.Delete(Ind);
    List.ItemIndex := Ind;
  end;
end;

procedure TJvRegEditor.PropAdd;
begin
  if List.Items.IndexOf(edtProp.Text) = -1 then
  begin
    List.Items.Add(edtProp.Text);
    List.ItemIndex := List.Items.IndexOf(edtProp.Text);
  end;
end;

procedure TJvRegEditor.PropDelete;
var
  It: Integer;
begin
  It := List.ItemIndex;
  List.Items.Delete(List.ItemIndex);
  if It > List.Items.Count - 1 then
    dec(It);
  if It < 0 then
    It := 0;
  List.ItemIndex := It;
  if List.Items.Count <> 0 then
    edtProp.Text := List.Items[List.ItemIndex];
end;

procedure TJvRegEditor.ListKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_DELETE then
    PropDelete;
  if List.Items.Count <> 0 then
    edtProp.Text := List.Items[List.ItemIndex];
end;

procedure TJvRegEditor.ListClick(Sender: TObject);
begin
  edtProp.Text := List.Items[List.ItemIndex];
end;

procedure TJvRegEditor.TreeEnter(Sender: TObject);
begin
  TreeChange(Sender, Tree.Selected);
end;

procedure TJvRegEditor.ListDrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  Offset: Integer; { text offset width }
  BitmapIndex: Integer;
  ComponentName: string[100];
  Obj: TComponent;
begin
  (Control as TListBox).Canvas.FillRect(Rect); { clear the rectangle }

  if Tree.Images <> nil then
  begin
    ComponentName := (Control as TListBox).Items[Index];
    ComponentName := Copy(ComponentName, 1, Pos('.', ComponentName) - 1);
    if ComponentName = Component.Owner.Name then
      ComponentName := '';
    if ComponentName = '' then
      BitmapIndex := 0
    else
    begin
      Obj := Component.Owner.FindComponent(ComponentName);
      if Obj <> nil then
        BitmapIndex := Obj.ComponentIndex + 1
      else
        BitmapIndex := imUnknown;
    end;
    inc(BitmapIndex, imComponent);

    TreeImages.Draw((Control as TListBox).Canvas, Rect.Left + 2, Rect.Top, BitmapIndex);
    Offset := TreeImages.width + 6; { add four pixels between bitmap and text }
  end
  else
    Offset := 2;
  (Control as TListBox).Canvas.TextOut(Rect.Left + Offset, Rect.Top, (Control as TListBox).Items[Index]);
    { display the text }
  //Note that the Rect parameter automatically provides the proper location of the item within the control's canvas.
end;

procedure TJvRegEditor.FormCreate(Sender: TObject);
begin
  //  if Tree.Images = nil then List.Style := lbStandard;
  with TSplitter.Create(Self) do
  begin
    Parent := Self;
    Align := alLeft;
    Left := 201;
    Beveled := False;
    Visible := True;
  end;
  with TJvRegAuto.Create(Self) do
  begin
    {$IFDEF DELPHI}
    RegPath := 'Software\Borland\Delphi\JVCL\JvRegAutoEditorForm';
    {$ENDIF DELPHI}
    {$IFDEF BCB}
    RegPath := 'Software\Borland\C++Builder\JVCL\JvRegAutoEditorForm';
    {$ENDIF BCB}
    AutoMode := True;
    SaveWindowPlace := True;
    Props.Add('Tree.Width');
    Load;
  end;
  edtProp.Hint := sRegAutoEditorEdtPropHint;
  Tree.Hint := sRegAutoEditorTreeHint;
  List.Hint := sRegAutoEditorListHint;
  btnAddProp.Hint := sRegAutoEditorBtnAddPropHint;
  Sort1.Caption := sRegAutoEditorSort;
end;

procedure TJvRegEditor.edtPropChange(Sender: TObject);
var
  Ind: Integer;
begin
  Ind := List.Items.IndexOf(edtProp.Text);
  if Ind <> -1 then
    List.ItemIndex := Ind;
end;

procedure TJvRegEditor.edtPropKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = ^M then
  begin
    btnAddPropClick(Sender);
    Key := #0;
  end;
end;

procedure TJvRegEditor.ListDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := (Source = Tree) and (List.Items.IndexOf(edtProp.Text) = -1);
end;

procedure TJvRegEditor.ListDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  if (Source = Tree) and (List.Items.IndexOf(edtProp.Text) = -1) then
    btnAddPropClick(Self);
  //  then PropAdd;
end;

procedure TJvRegEditor.TreeDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := (Source = List) and (List.Items.IndexOf(edtProp.Text) <> -1);
end;

procedure TJvRegEditor.TreeDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  if (Source = List) and (List.Items.IndexOf(edtProp.Text) <> -1) then
    btnAddPropClick(Self);
  //  then PropDelete;
end;

procedure TJvRegEditor.ListEnter(Sender: TObject);
begin
  btnAddProp.Enabled := True;
end;

procedure TJvRegEditor.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if FProps <> Component.Props.Text then
    FModified := True;
end;

procedure TJvRegEditor.Sort1Click(Sender: TObject);
begin
  List.Sorted := True;
  //  List.Sorted := False;
end;

function GetProjectName: string;
begin
  if Assigned(ToolServices) then
    Result := ToolServices.GetProjectName
  else
    Result := '';
end;

initialization
  GetProjectNameProc := GetProjectName;
  
end.

⌨️ 快捷键说明

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