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

📄 objectinspec.pas

📁 一个模拟Delphi的快速开发环境RAD
💻 PAS
📖 第 1 页 / 共 3 页
字号:
   end
   else if Editor.ClassName='TFontProperty' then SetEditBounds(Browse)
   else if Editor.ClassName='TPictureProperty' then SetEditBounds(Browse)
   else if Editor.ClassName='THD_PictureProperty' then SetEditBounds(Browse)
   else if Editor.ClassName='THD_StringListProperty' then SetEditBounds(Browse)
   else if (Editor.ClassName ='TMethodProperty') then SetEditBounds(edEvent)
   else if  (Editor.ClassName ='THD_MenuItemProperty') then  SetEditBounds(Browse)
   else if  (Editor.GetPropType.Name='TBitmap') then  SetEditBounds(Browse)
   else if  (Editor.GetPropType.Name='TPopupMenu') then  SetEditBounds(cbValue)
   else if  (Editor.GetPropType.Name='TListColumns') then  SetEditBounds(Browse);
  // else  SetEditBounds(edProperty);
   StatusBar1.SimpleText:=Editor.GetPropType.Name+' : '+Editor.ClassName;
   // 加己捞 捞亥飘啊 酒聪搁 加己蔼阑 盎脚茄促.
   if (Editor.ClassName<>'TMethodProperty') then  UpdateValue;
  // edProperty.Text:=GetPropertyValueName;
   if edProperty.Visible then  edProperty.Text:= Editor.GetValue
   else if cbValue.Visible then  SetcbValueIndex(Editor.GetValue);
end;

{ Callback for getting a subproperty editor. }
procedure TObjectInspector.GetPropEditor(Editor: TPropertyEditor);
begin
   Editor.Initialize;
   PropertyList.AddObject(Editor.GetName, Editor);
end;

// Font客 鞍捞 SubProperties甫 爱绰 加己狼 窍困 加己阑
// 焊咯林绰 Callback 橇肺矫历
procedure TObjectInspector.GetSubPropEditor(Editor: TPropertyEditor);
var
  Prop:string;
begin
   Editor.Initialize;
   Prop:= Format('  %-18s%-s',[Editor.GetName, Editor.GetValue]);
   PropertyList.InsertObject(PropertyBox.ItemIndex + 1, Editor.GetName, Editor);
   PropertyBox.Items.Insert(PropertyBox.ItemIndex + 1, Prop);
end;

procedure TObjectInspector.GetEventEditor(Editor: TPropertyEditor);
begin
   EventList.AddObject(Editor.GetName, Editor);
end;

// 哪欺惩飘啊 啊瘤绊 乐绰 加己苞 弊 蔼阑 焊咯霖促.
procedure TObjectInspector.GetProperties(Component: TComponent);
var
  CompList: TComponentList;    // 加己 格废   历厘
  Comp1List: TComponentList;   // 捞亥飘 格废 历厘
begin
  PropertyList.BeginUpdate;
  EventList.BeginUpdate;
  ClearProperties;
  CompList := TComponentList.Create;
  Comp1List := TComponentList.Create;
  try
    CompList.Add(Component);
    Comp1List.Add(Component);
    // 哪欺惩飘Component俊 措茄 加己 祈笼扁甫 积己茄促.(加己俊 措茄 祈笼扁)
    GetComponentProperties(CompList, tkProperties,ProxyDesigner , GetPropEditor);
    // 哪欺惩飘俊 措茄 加己(捞亥飘)俊 措茄 加己 祈笼扁甫 积己茄促.(葛电 捞亥飘)
    GetComponentProperties(Comp1List, tkMethods, ProxyDesigner, GetEventEditor);
  finally
    CompList.Free;
    Comp1List.Free;
  end;
  PropertyList.EndUpdate;
  EventList.EndUpdate;
end;

{ Initialize the property editor form. }
procedure TObjectInspector.Initialize(Component: TComponent);
begin
  Designer := ProxyDesigner;
  fComponent := Component;
end;

procedure TObjectInspector.FormCreate(Sender: TObject);
begin
   URegister.Register;   // 葛电 加己 祈笼扁甫 殿废茄促.
   PropertyList:=TStringList.Create;
   EventList:=TStringList.Create;
   Left:=0;
   PageControl1.ActivePage:=TabProperty;
   ComponentList.Items.Add('Form1:TForm1');
end;

procedure TObjectInspector.FormResize(Sender: TObject);
begin
   // 汽狼 农扁啊 官拆 版快 阿 牧飘费狼 承捞甫 犁炼沥茄促.
   ComponentList.Width:=Width-10;
   EditRect.Right := PropertyBox.ItemRect(PropertyBox.ItemIndex).Right;
   if Browse.Visible then SetEditBounds(Browse)
   else if edProperty.Visible then SetEditBounds(edProperty)
   else if edEvent.Visible then SetEditBounds(edEvent)
   else if cbValue.Visible then SetEditBounds(cbValue);
end;

// 坷宏璃飘 牢胶棋飘狼 哪欺惩飘 格废俊辑 哪欺惩飘 捞抚父 眠免茄促.
function TObjectInspector.ExtractComponentName(const S:string):string;
var
  SepaPos:integer;
begin
   Result:='';
   SepaPos:=Pos(':',S);
   if SepaPos>1 then Result:=Copy(S,1,SepaPos-1);
end;

// 泅犁 急琶茄 哪欺惩飘狼 捞抚阑 倒妨霖促.
function TObjectInspector.GetComponentName: string;
begin
  with ComponentList do
    if ItemIndex<0 then   Result := ''
    else  Result := ExtractComponentName(Items[ItemIndex]);
end;

// Object Inspector俊辑 急琶茄 哪欺惩飘甫 倒妨霖促.
// 厚矫阿利 哪欺惩飘甫 急琶茄 版快俊绰 Wrapper俊 WrapperControl甫 且寸茄促.
function TObjectInspector.GetComponent(var Wrapper:TComponent): TComponent;
var
  WrapperName,ComponentName:string;
  Component:TComponent;
begin
  Wrapper:=nil;
  ComponentName:= GetComponentName;
  WrapperName:='Wrapper'+ComponentName;
  if ComponentName = ProxyDesigner.Form.Name then
    Result := ProxyDesigner.Form
  else begin
    Component:= ProxyDesigner.Form.FindComponent(WrapperName);
    if Component<>nil then  Wrapper:=Component;
    Result := ProxyDesigner.Form.FindComponent(ComponentName);
  end;
end;

// 哪欺惩飘俊 措茄 坷宏璃飘 牢胶棋飘 沥焊甫 焊咯霖促.
// 厚矫阿利 哪欺惩飘老 版快俊绰 加己篮 厚矫阿利 哪欺惩飘甫 焊咯林绊, 汽俊辑绰
// 厚矫阿利 哪欺惩飘狼 Wrapper哪欺惩飘甫 急琶茄促.
// 厚矫阿利 哪欺惩飘老 版快俊绰 Wrapper捞 nil酒 酒丛
procedure TObjectInspector.DisplayProperty(Wrapper,Component:TComponent);
var
  Name:string;
begin
   if Component<>nil then begin
      SetEditBounds(nil);   // 祈笼侩 牧飘费阑 焊捞瘤 臼霸 茄促.
      GetPropertyInfo(TObject(Component));
      if Wrapper<>nil then   ProxyDesigner.SelectComponent(Wrapper)
      else ProxyDesigner.SelectComponent(Component);
      if Component is TForm then Name:= 'TForm'
      else Name:= Component.ClassName;
      SelectComponent:= Component;
      ComponentList.ItemIndex:= ComponentList.Items.IndexOf(Component.Name+':'+Name);
   end;
end;

procedure  TObjectInspector.EditorProperty;
begin
   if (PropertyEditor <> nil) then begin
       PropertyEditor.Edit;
       UpdateValue;
   end;
   SetPropertyValueName(PropertyEditor.GetValue);
end;

// 加己狼 蔼阑 Value肺 汲沥茄促.
procedure TObjectInspector.PropSetValue(const Value: string);
begin
   if PropertyEditor <> nil then begin
      PropertyEditor.SetValue(Value);
      UpdateValue;
   end;
end;

procedure TObjectInspector.UpdateValue;
begin
  // if PropertyEditor<> nil then
  //     SetPropertyValueName(PropertyEditor.GetValue);
end;

// 加己捞 啊瘤绰 凯芭屈 蔼肚绰 笼钦阑 倒妨霖促.(巩磊凯)
function TObjectInspector.GetPropValue(Info:PPropInfo):TStringList;
var
   Data:PTypeData;
   I,MinVal,MaxVal: Integer;
   ValueList: TStringList;
   TypeInfo1 :PTypeInfo;
begin
   ValueList:=TStringList.Create;
   Data:= GetTypeData(Info^.PropType^);
   case Info^.PropType^.Kind of
        tkEnumeration: begin
           for I:=Data.MinValue to Data.MaxValue do
               ValueList.Add(GetEnumName(Info^.PropType^,I));
           end;
           tkSet: begin
               Data:=GetTypeData(Info^.PropType^);
               TypeInfo1:=Data^.CompType^;
               Data:=GetTypeData(TypeInfo1);
               MinVal:=Data^.MinValue;
               MaxVal:=Data^.MaxValue;
               for I:=MinVal to MaxVal do
                  ValueList.Add(GetEnumName(TypeInfo1,I));
            end;
   end;
   Result:= ValueList;
end;

// 加己狼 type俊 蝶扼 加己蔼阑 涝仿且 牧飘费阑 搬沥茄促.
procedure TObjectInspector.SetEditBounds(AControl : TWinControl);
var
  Index: Integer;
begin
  // 加己捞 凯芭屈 肚绰 笼钦屈牢 版快, 加己蔼 霓焊 冠胶甫 加己 困摹俊 嘎眠绊,
  // 弊犯瘤 臼栏搁 霓焊 冠胶甫 焊捞瘤 臼霸 茄促.
  if AControl<>nil then with AControl do
  begin
    if AControl=cbValue then begin
      cbValue.SetBounds(EditRect.Left+1,EditRect.Top,
                 EditRect.Right-EditRect.Left+3,EditRect.Bottom - EditRect.Top);
      cbValue.Visible:=True;
      Browse.Visible:=False;
      edProperty.Visible:= False;
      cbValue.SetFocus;
      Index:= cbValue.Items.IndexOf(GetPropertyValueName);
      if Index<>-1 then cbValue.ItemIndex:= Index
      else cbValue.Text:= GetPropertyValueName;
    end
    else if AControl=edProperty then begin
      edProperty.SetBounds(EditRect.Left+1,EditRect.Top,
                 EditRect.Right-EditRect.Left+3,EditRect.Bottom - EditRect.Top);
      cbValue.Visible:=False;
      Browse.Visible:=False;
      edProperty.Visible:= True;
     // edProperty.SetFocus;
    end
    else if AControl=Browse then begin
      Browse.SetBounds(EditRect.Right-15,EditRect.Top,Browse.Width,EditRect.Bottom - EditRect.Top);
      Visible:=True;
      Browse.SetFocus;
      cbValue.Visible:=False;
      edProperty.Visible:= False;
    end
    else if AControl=edEvent then begin
      edEvent.SetBounds(EditRect.Left+1,EditRect.Top,
                 EditRect.Right-EditRect.Left+3,EditRect.Bottom - EditRect.Top);
      edEvent.Width:= EventBox.ClientWidth - HalfWay;
      edEvent.Text:= Copy(EventBox.Items[EventBox.ItemIndex], 21, 255);
      Visible:=True;
      edEvent.SetFocus;
    end;
  end
  else begin
     cbValue.Visible:=False;
     Browse.Visible:=False;
     edProperty.Visible:= False;
  end;
end;

procedure TObjectInspector.ComboValueChange(Sender: TObject);
begin
   PropSetValue(cbValue.Text);
end;

// 捞亥飘俊 措茄 家胶 内靛甫 积己茄促.
procedure TObjectInspector.StringGrid2DblClick(Sender: TObject);
var
   EventName: string;
   EventHandler:string;
begin
    EventName:=ExtractComponentName(ComponentList.text);
   //// with StringGrid2 do
   ////    EventName:=EventName+Copy(Cells[0,Row],3,Length(Cells[0,Row]));
    EventHandler:=EventName;
    // 捞亥飘狼 颇府固磐甫 炼荤茄促.
    EventName:=EventName+'('+WriteMethodData(GetTypeData(PropertyEditor.GetPropType))+');';
    // 捞亥飘 勤甸矾甫 累己窍瘤 臼疽栏搁 捞亥飘 勤甸矾甫 累己窍绊, 内靛 祈笼扁甫 劝己拳茄促.
  ////  if  StringGrid2.Cells[1,StringGrid2.Row]='' then   EditorForm.WriteEventCode(EventName)
  ////  else EditorForm.MoveToString(EventName);
  ////  StringGrid2.Cells[1,StringGrid2.Row]:=EventHandler;
end;

{ Get a value from the list of string values. }
procedure TObjectInspector.GetValueProc(const Value: string);
begin
   cbValue.Items.Add(Value);
end;

procedure TObjectInspector.PropertyBoxDrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  sr,dr: TRect;
  PropName,PropValue:string;
begin
  with (Control as TListBox).Canvas do
  begin
    Brush.Color := PropertyBox.Color;          {Won't use Windows Selected color.}
    fillRect(Rect);

    // 啊肺急阑 弊覆
    if (odSelected in State) then Pen.Color := clBtnHighLight else {for 3D look}
      Pen.Color := clBtnShadow;
    Pen.Mode := pmCopy;
    Pen.Width := 1;
    Pen.Style := psSolid;
    MoveTo(Rect.Left, Rect.Bottom-1);
    LineTo(Rect.Right, Rect.Bottom-1);

    // Item狼 吝埃俊 靛贰弊甫 困茄 荐流急阑 弊覆
    if (odSelected in State) then begin
      Pen.Color := clBtnHighLight;
      MoveTo(HalfWay + 2, Rect.Top+1);
      LineTo(Halfway + 2, Rect.Bottom);

      Pen.Color := clBtnShadow;
      MoveTo(Halfway+1, Rect.Top+2);
      LineTo(Halfway+1, Rect.Bottom);

      MoveTo(Rect.Right, Rect.Top);
      LineTo(Rect.Left, Rect.Top);
      LineTo(Rect.Left, Rect.Bottom);

      Pen.Color := clBlack;
      MoveTo(Rect.Right-1, Rect.Top+1);
      LineTo(Rect.Left+1, Rect.Top+1);
      LineTo(Rect.Left+1, Rect.Bottom-1);
    end
    else begin
      Pen.Color := clBtnShadow;
      MoveTo(Halfway, Rect.Top+1);
      LineTo(Halfway, Rect.Bottom);

      Pen.Color := clBtnHighLight;
      MoveTo(HalfWay + 1, Rect.Top+1);
      LineTo(Halfway + 1, Rect.Bottom);
    end;

    SR.Left := Rect.Left+2 ;  SR.Right := HalfWay;
    SR.Top := Rect.Top+1;  SR.Bottom := Rect.Bottom-1;

    if (odSelected in State) then begin
      Inc(SR.Left);
      Inc(SR.Top);
      Inc(SR.Right);
    end;
    // Item狼 加己疙苞 加己蔼阑 免仿
    Font.Color := clBlack;
    setbkMode(PropertyBox.Canvas.Handle, Transparent);
    PropName:= Copy(PropertyBox.Items[Index],1,20);
    PropValue:= Copy(PropertyBox.Items[Index],21,255);
    if PropName[1] = '+' then
       TextRect(SR, Sr.Left, SR.Top, PropName )
    else
       TextRect(SR, Sr.Left+10, SR.Top, PropName );
    Font.Color := clNavy;
    TextOut(HalfWay + 4, SR.Top-2, PropValue );

    DR.Left := Rect.Left+2;  DR.Right := Rect.Left+13+2;  {DestRect}
    DR.Top := Rect.Top+1; DR.Bottom := Rect.Top+13+1;

    if (odSelected in State) then begin       { To give 3D look to inspector.}
      Inc(DR.Left); Inc(DR.Right);
      Inc(DR.Top); Inc(DR.Bottom);
      if cbValue.Visible then begin
      // PropertyBox甫 胶农费矫 cbValue狼 困摹甫 犁炼沥茄促.
        with Rect do begin
           if (Top <= 0) and (PropertyBox.ItemIndex <> 0) then
              cbValue.Visible:= False
           else if (Bottom > PropertyBox.Height) then
              cbValue.Visible:= False
           else cbValue.SetBounds(HalfWay+4, Top+2, Right-HalfWay, Bottom-Top);
        end;
      end;
    end;
  end;
  if (not edProperty.Focused) and (odselected in state) then begin
      edProperty.Visible:= False;
      with PropertyBox.Canvas do begin
         EditRect := PropertyBox.ItemRect(PropertyBox.ItemIndex);
         EditRect.Left := HalfWay + 4;
         Brush.Color := clWhite;
         Inc(EditRect.Top,3);
         FillRect(EditRect);
         setbkColor(PropertyBox.Canvas.Handle, GetsysColor(color_HighLight));
         setbkMode(PropertyBox.Canvas.Handle, Opaque);
         Font.Color := clhighlightText;
         Canvas.Brush.Color := clHighlight;
         TextOut(EditRect.Left, EditRect.Top, PropValue);
         DestroyCaret;
         Createcaret(PropertyBox.Handle, 0, 1, (EditRect.Bottom - Editrect.Top) - 2);
         SetCaretPos(EditRect.Left + TextWidth(PropValue), EditRect.Top+1);
         ShowCaret(PropertyBox.Handle);
      end;
  end
 // if (odFocused in State) and (odselected in state) then
 //     (Control as TListbox).Canvas.DrawFocusRect(rect);
end;

procedure TObjectInspector.PropertyBoxMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  R,sr : TRect;
begin
  if Abs(X - Halfway) <= 3 then  SplitDrag := True
  else
  if (X >= EditRect.left) and (X <= EditRect.Right) and
     (y >= EditRect.Top) and (Y <= EditRect.Bottom) then begin
     PropertyBox.Cursor := crDefault;
    // SetEditor(PropertyList.Objects[PropertyBox.ItemIndex] as TPropertyEditor)
  end;
end;

procedure TObjectInspector.PropertyBoxMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
var
  TempR : TRect;
  LB : TListBox;
begin
  if PageControl1.ActivePage = TabProperty then  Lb := PropertyBox
  else lb := EventBox;
  if SplitDrag then begin
    if X > Lb.ClientWidth - 20 then X := Lb.ClientWidth - 20;
    if X < 20 then X := 20;

    if Halfway < X then TempR:= Rect(Halfway, 0, lb.ClientWidth, lb.ClientHeight)
    else  TempR:= Rect(X, 0, lb.ClientWidth, lb.ClientHeight);
    HalfWay := X;

    InvalidateRect(lb.Handle, @TempR, False);
    InvalidateRect(lb.Handle, @EditRect, False);
    PostMessage(lb.Handle, WM_Paint, 0, 0);
    Exit;

⌨️ 快捷键说明

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