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

📄 objectinspec.pas

📁 一个模拟Delphi的快速开发环境RAD
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  end;
  if Abs(x - Halfway) <= 3 then   lb.Cursor := crHSplit
  else
  if (X >= EditRect.left) and (X <= EditRect.Right) and
     (Y >= EditRect.Top) and (Y <= EditRect.Bottom) then
       lb.Cursor := crIBeam else lb.Cursor := crDefault;
end;

procedure TObjectInspector.PropertyBoxMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
   SplitDrag := False;
end;

procedure TObjectInspector.FormShow(Sender: TObject);
begin
  Halfway := PropertyBox.Width div 2;
end;

procedure TObjectInspector.EventBoxDrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  SR,DR: TRect;
  EventName,EventValue:string;
begin
  with (Control as TListBox).Canvas do
  begin
    Brush.Color := EventBox.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(EventBox.Canvas.Handle, Transparent);
    EventName:= Copy(EventBox.Items[Index],1,20);
    EventValue:= Copy(EventBox.Items[Index],21,255);
    TextRect(SR, Sr.Left + 10, SR.Top, EventName);
    Font.Color := clNavy;
    TextOut(HalfWay + 4, SR.Top, EventValue );

    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);
    end;
  end;

  if (not edEvent.Focused) and (odselected in state) then
      with EventBox.Canvas do begin
         EditRect := EventBox.ItemRect(EventBox.ItemIndex);
         EditRect.Left := HalfWay + 2;
         Brush.Color := clWhite;
         Inc(EditRect.Top,4);
         Fillrect(EditRect);
         setbkColor(EventBox.Canvas.Handle, GetsysColor(color_HighLight));
         setbkMode(EventBox.Canvas.Handle, Opaque);
         Font.Color := clhighlightText;
         Canvas.Brush.Color := clHighlight;
         TextOut(EditRect.Left, EditRect.Top, EventValue);
         DestroyCaret;
         Createcaret(EventBox.Handle, 0, 1, (EditRect.Bottom - Editrect.top) - 2);
         SetCaretPos(EditRect.Left + TextWidth(EventValue), EditRect.Top+1);
         ShowCaret(EventBox.handle);
      end;
  if (odFocused in State) and (odselected in state) then
      (Control as TListbox).Canvas.DrawFocusRect(Rect);
end;

procedure TObjectInspector.EventBoxMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  P : TPoint;
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
     P:= Point(X,Y);
     EventBox.Cursor := crDefault;
   //  ShowEventInput;
     MapWindowPoints(EventBox.Handle, edEvent.Handle, P, 1);
     PostMessage(edEvent.Handle, WM_LButtonDown, mk_lbutton, P.Y shl 16 + P.X);
  end;
end;

procedure TObjectInspector.EventBoxMouseMove(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;
  end;
  if Abs(x - Halfway) <= 3 then   lb.Cursor := crHSplit
  else
  if (X >= EditRect.left) and (X <= EditRect.Right) and
     (Y >= EditRect.Top) and (Y <= EditRect.Bottom) then
       lb.Cursor := crIBeam else lb.Cursor := crDefault;
end;

procedure TObjectInspector.EventBoxMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
   if SplitDrag then begin   // 靛贰弊啊 场唱搁 牧飘费狼 困摹甫 犁炼沥
      edEvent.Left := EditRect.left;
      edEvent.Top := EditRect.Top;
      edEvent.Width := EditRect.Right - EditRect.Left;
      edEvent.Height := EditRect.Bottom - EditRect.Top;
   end;
   SplitDrag := False;
end;

// ListBox狼 ItemIndex狼 加己疙阑 倒妨霖促.
function TObjectInspector.GetPropertyName: string ;
begin
   Result:='';
   if PropertyBox.ItemIndex = -1 then Exit;
   Result:= Trim(Copy(PropertyBox.Items[PropertyBox.ItemIndex],1,20));
end;

// ListBox狼 ItemIndex狼 捞亥飘疙阑 倒妨霖促.
function TObjectInspector.GetEventName: string ;
begin
   Result:='';
   if EventBox.ItemIndex = -1 then Exit;
   Result:= Trim(Copy(EventBox.Items[EventBox.ItemIndex],1,20));
end;

// ListBox狼 ItemIndex狼 加己蔼阑 倒妨霖促.
function TObjectInspector.GetPropertyValueName: string ;
begin
   Result:='';
   if PropertyBox.ItemIndex = -1 then Exit;
   Result:= Trim(Copy(PropertyBox.Items[PropertyBox.ItemIndex],21,255));
end;

// ListBox狼 ItemIndex狼 捞亥飘蔼阑 倒妨霖促.
function TObjectInspector.GetEventValueName: string ;
begin
   Result:='';
   if EventBox.ItemIndex = -1 then Exit;
   Result:= Trim(Copy(EventBox.Items[EventBox.ItemIndex],21,255));
end;

// ListBox狼 ItemIndex狼 加己蔼阑 汲沥茄促.
procedure TObjectInspector.SetPropertyValueName(Value:string) ;
begin
   if PropertyBox.ItemIndex = -1 then Exit;
   with PropertyBox do
      Items[ItemIndex]:= Copy(Items[ItemIndex],1,20)+ Value;
end;

// 努腐茄 加己狼 加己 祈笼扁甫 汲沥茄促.
procedure TObjectInspector.PropertyBoxClick(Sender: TObject);
begin
   with PropertyList do
      if PropertyList.Count>0 then
         SetEditor(Objects[PropertyBox.ItemIndex] as TPropertyEditor)
      else SetEditor(nil);
end;

procedure TObjectInspector.PropertyBoxKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if key = vk_return then begin
    Key := 0;
    exit;
  end;
  if not (Key in [vk_up, vk_down, vk_prior, vk_next]) then begin
    edProperty.left := EditRect.left;
    edProperty.Top := EditRect.Top;
    edProperty.Width := EditRect.Right - EditRect.Left;
    edProperty.Height := EditRect.Bottom - EditRect.Top;
    edProperty.Visible := True;
    edProperty.SetFocus;
    PostMessage(edProperty.Handle, WM_KeyDown, Key, 0);
    Key := 0;
  end;
end;

procedure TObjectInspector.EventBoxClick(Sender: TObject);
begin
   with EventList do
      if Count>0 then
         SetEditor(Objects[EventBox.ItemIndex] as TPropertyEditor)
      else  SetEditor(nil);
end;

// 加己蔼狼 格废阑 歹喉努腐窍绰 版快, 蔼阑 瞒肥肺 官操绊, 加己蔼阑 盎脚茄促.
// ListBox狼 Style 加己捞 csDropDown栏肺 汲沥登绢 乐绰 版快俊父 啊瓷窃
procedure TObjectInspector.cbValueDblClick(Sender: TObject);
begin
   with cbValue do begin
      if ItemIndex<0 then ItemIndex:=0
      else if ItemIndex=(Items.Count-1) then ItemIndex:=0
      else ItemIndex:=ItemIndex+1;
      cbValueChange(self);
   end;
end;

procedure TObjectInspector.BrowseClick(Sender: TObject);
begin
   EditorProperty;
end;

procedure TObjectInspector.edPropertyKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
   case Key of
     VK_DOWN:
        if PropertyBox.ItemIndex< (PropertyBox.Items.Count-1) then begin
           if edProperty.Modified then begin //Edit狼 郴侩捞 荐沥登菌栏搁
              PropSetValue(edProperty.Text);
              with PropertyBox do
                 Items[ItemIndex]:= Format('%-20s',[GetPropertyName]) + edProperty.Text;
           end;
        end;
     VK_UP:
        if PropertyBox.ItemIndex >= 1 then begin
           if edProperty.Modified then begin //Edit狼 郴侩捞 荐沥登菌栏搁
              PropSetValue(edProperty.Text);
              with PropertyBox do
                 Items[ItemIndex]:= Format('%-20s',[GetPropertyName]) + edProperty.Text;
           end;
        end;
   end;
   if (Key in [vk_up, vk_down, vk_prior, vk_next]) then begin
      PropertyBox.SetFocus;
      PostMessage(PropertyBox.Handle, WM_KeyDown, Key, 0);
      Key := 0;
   end;
end;

procedure TObjectInspector.edPropertyKeyPress(Sender: TObject;
  var Key: Char);
begin
   if Key=#13 then begin
      PropertyBox.SetFocus;
      PropSetValue(edProperty.Text);
      with PropertyBox do
         Items[ItemIndex]:= Format('%-20s',[GetPropertyName]) + edProperty.Text;
   end;
end;

procedure TObjectInspector.cbValueChange(Sender: TObject);
begin
   PropSetValue(cbValue.Text);
   with PropertyBox do
       Items[ItemIndex]:= Format('%-20s',[GetPropertyName]) + cbValue.Text;
end;

procedure TObjectInspector.cbValueKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if Key = vk_Return then Begin
      PropertyBox.SetFocus;
      Key := 0;
      Exit;
   end;
   if (Key in [vk_up, vk_down, vk_prior, vk_next]) then begin
      PropertyBox.Setfocus;
      PostMessage(PropertyBox.Handle, WM_KeyDown, Key, 0);
      Key := 0;
   end;
end;

procedure TObjectInspector.cbValueDrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  with (Control as TComboBox).Canvas do
  begin
    FillRect(Rect);
   // Font.Color := clNavy;
    TextOut(Rect.Left, Rect.Top, cbValue.Items[Index]);
  end;
end;

procedure TObjectInspector.FormActivate(Sender: TObject);
begin
  ComponentList.ItemIndex:=0;
end;

// 货肺款 汽阑 累己窍芭唱 汽 荤捞甫 傈券且 锭 Object Inspector狼 沥焊甫
// 汽俊 嘎霸 促矫 佬绰促.
procedure TObjectInspector.InitializeInspector;
var
  I:Integer;
begin
   ComponentList.Clear;
   ComponentList.Items.Add(ProxyDesigner.Form.Name+':TForm');
   with ProxyDesigner.Form do  begin
    for I:=0 to  ComponentCount-1 do
        if (Components[I].ClassType<>TGrabHandle) and (Components[I].ClassType<>TWrapperControl) then
           ComponentList.Items.Add(Components[I].Name+':'+Components[I].ClassName)
    end;
    ComponentList.ItemIndex:=0;
end;

// 哪欺惩飘 格废俊辑 哪欺惩飘甫 急琶窍绰 版快, 秦寸 哪欺惩飘甫 急琶窍绊 加己阑 焊咯霖促.
procedure TObjectInspector.ComponentListClick(Sender: TObject);
var
  Component:TComponent;
  Wrapper:TComponent;
begin
   Component := GetComponent(Wrapper);
   DisplayProperty(Wrapper,Component);
end;

procedure TObjectInspector.edEventDblClick(Sender: TObject);
var
   EventName: string;
   EventHandler:string;
begin
    EventName:=ExtractComponentName(ComponentList.text);
    with EventBox do
       EventName:= Trim(EventName+Copy(Items[ItemIndex],3,20));
    EventHandler:= EventName;
    // 捞亥飘狼 颇府固磐甫 炼荤茄促.
    EventName:=EventName+'('+WriteMethodData(GetTypeData(PropertyEditor.GetPropType))+');';
    // 捞亥飘 勤甸矾甫 累己窍瘤 臼疽栏搁 捞亥飘 勤甸矾甫 累己窍绊, 内靛 祈笼扁甫 劝己拳茄促.
    if  edEvent.Text = '' then   EditorForm.WriteEventCode(EventName)
    else EditorForm.MoveToString(EventName);
    with EventBox do
       Items[ItemIndex]:=
          Format('%20s%s',[Copy(Items[ItemIndex],1,20),EventHandler]);
end;

procedure TObjectInspector.PropertyBoxDblClick(Sender: TObject);
var
  Po:TPoint;
  PropInfo:PPropInfo;
  PropName:string;
  Editor:TPropertyEditor;
begin
   GetCursorPos(Po);
   Po:= PropertyBox.ScreenToClient(Po);
   if Po.x < HalfWay then begin
      if PropertyBox.Items[PropertyBox.ItemIndex][1] = '+' then  begin
         PropName:= Trim(Copy(PropertyBox.Items[PropertyBox.ItemIndex],2,20));
         PropertyBox.Items[PropertyBox.ItemIndex]:= '-' + PropName;
         //PropInfo:= GetPropInfo(SelectComponent.ClassInfo, PropName);
         //InsertPropInfo(PropInfo, SelectComponent);
         Editor:= TPropertyEditor(PropertyList.Objects[PropertyBox.ItemIndex]);
         if Editor <> nil then
            Editor.GetProperties(GetSubPropEditor);
      end
      else if PropertyBox.Items[PropertyBox.ItemIndex][1] = '-' then  begin
         PropName:= Trim(Copy(PropertyBox.Items[PropertyBox.ItemIndex],2,20));
         PropertyBox.Items[PropertyBox.ItemIndex]:= '+' + PropName;
         PropInfo:= GetPropInfo(SelectComponent.ClassInfo, PropName);
         DeletePropInfo(PropInfo, SelectComponent);
      end;
   end;
end;

//cbValue狼 ItemIndex甫 Text阑 啊瘤绰 牢郸胶肺 汲沥茄促.
// cbValue狼 Style甫 csDropDownList肺 汲沥沁扁 锭巩俊
// cbValue.Text:= Text鄂 巩厘捞 家侩捞 绝扁 锭巩捞促.
procedure TObjectInspector.SetcbValueIndex(Text:string);
var
  Index:Integer;
begin
   Index:= cbValue.Items.IndexOf(Text);
   if Index<>-1 then cbValue.ItemIndex:= Index
   else cbValue.Text:= GetPropertyValueName;
end;

end.

⌨️ 快捷键说明

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