Mega Code Archive

 
Categories / Delphi / Examples
 

Object inspector uniti

//www.programlama.com 'dan örnek unit Inspector; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, Grids, Menus, ExtCtrls, ImgList, Contnrs, TypInfo{, DesignIntf, DesignEditors}, ValEdit; type TInsForm = class(TForm) StatusBar1: TStatusBar; cmbCompList: TComboBox; editValue: TEdit; PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; Panel1: TPanel; StringGrid1: TStringGrid; cmbValueList: TComboBox; procedure FormCreate(Sender: TObject); procedure FormResize(Sender: TObject); procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormDestroy(Sender: TObject); procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure cmbCompListClick(Sender: TObject); procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure cmbValueListDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); private { Private declarations } public { Public declarations } procedure Listele; procedure Doldur; end; var InsForm: TInsForm; ContSelList: TComponentList; Pinf : PPropInfo; PList: PPropList; C: TComponent; Foo: Boolean; boolIcon: Boolean; function ParcaAl(AStr:String;P1:Boolean=True):string; implementation {$R *.dfm} function ParcaAl(AStr:String;P1:Boolean=True):string; var j:Byte; begin for j:=0 to length(AStr)-1 do begin if AStr[j]='#' then begin if P1 then Result:=Copy(AStr,0,j-1) else Result:=Copy(AStr,j+1,length(AStr)-j); exit; end; end; Result:=AStr; end; procedure TInsForm.Doldur(); var PropCount,j,i: integer; s,s2: string; f:Real; E:TComponent; begin cmbValueList.Clear; cmbValueList.Sorted:=true; StringGrid1.RowCount:=0; C:=FindComponent (cmbCompList.Text); if C=nil then C:=ContSelList.Items[0]; //c:=cmbCompList; PropCount:=GetTypeData(C.ClassInfo).PropCount; GetMem(PList,sizeof(Pinf)* PropCount ); GetPropInfos(C.ClassInfo,Plist); for j:=0 to PropCount - 1 do begin case PList[j]^.PropType^.Kind of tkString,tkLString,tkWString: begin s := GetStrProp(c,PList[j]^.Name); end; tkChar,tkWChar: // password char sorun ??? begin s:=copy(GetStrProp(c,PList[j]^.Name),1,1); end; tkEnumeration: begin s := GetEnumProp(c,PList[j]^.Name); end; tkInteger: begin i := GetOrdProp(c,PList[j]^.Name); s := IntToStr(i) end; tkFloat: begin f := GetFloatProp(c,PList[j]^.Name); s := FloatToStrF(f,ffGeneral,28,28); end; tkClass: begin E:=TComponent(GetObjectProp(c,Plist[j]^.name)); if E <> nil then s:=E.GetNamePath else s:=' '; end; tkSet: begin s:=GetSetProp(c,PList[j]^.name,True); end; else begin s:="; end; end; if s<>" then begin cmbValueList.Items.Add(PList[j]^.Name + '#' + s); end; end; StringGrid1.RowCount:=cmbValueList.Items.Count; for i:=0 to cmbValueList.Items.Count-1 do begin if GetPropInfo(C,ParcaAl(cmbValueList.Items.Strings[i])).PropType^.Kind =tkClass then begin boolIcon:=True; StringGrid1.Cells[0,i]:=' +' + ParcaAl(cmbValueList.Items.Strings[i]); end else begin StringGrid1.Cells[0,i]:=' ' + ParcaAl(cmbValueList.Items.Strings[i]); end; boolIcon:=False; StringGrid1.Cells[1,i]:=' ' + ParcaAl(cmbValueList.Items.Strings[i],false); end; FreeMem(PList,sizeof(Pinf)* PropCount); cmbValueList.Clear; StatusBar1.Panels.Items[0].Text:=inttostr(StringGrid1.RowCount) + ' Properties'; end; procedure TInsForm.Listele; var i:integer; begin cmbCompList.Clear; for i:=0 to ContSelList.Count-1 do begin cmbCompList.Items.Add(ContSelList.Items[i].Name); end; cmbCompList.ItemIndex :=0; end; procedure TInsForm.FormCreate(Sender: TObject); begin //////////////// ContSelList:=TComponentList.Create; ContSelList.Add(TComponent (InsForm)); ContSelList.Add(TComponent (StatusBar1)); ContSelList.Add(TComponent (cmbCompList)); //ContSelList.Add(TComponent (PopupMenu1)); Listele; { cmbCompList.Items.AddObject(InsForm.Name,InsForm); cmbCompList.Items.AddObject(StatusBar1.Name,StatusBar1); cmbCompList.Items.AddObject(cmbCompList.Name,cmbCompList); } ///////////////// //cmbCompListClick(cmbCompList); Doldur; with cmbCompList do begin Left:=0; Top:=0; Width:=Self.ClientWidth; Anchors:=[akLeft,akTop,akRight]; end; with PageControl1 do begin Left:=0; Top:=cmbCompList.Height+2; Width:=Self.ClientWidth; Anchors:=[akLeft,akTop,akRight]; end; with StringGrid1 do begin left:=0; top:=PageControl1.Top + PageControl1.Height; Height:=self.ClientHeight -PageControl1.Height -cmbCompList.Height -StatusBar1.Height-4; Width:=Self.ClientWidth-2; Anchors := [akLeft,akTop,akRight,akBottom]; end; StringGrid1.ColWidths[0]:=(StringGrid1.ClientWidth ) div 2; StringGrid1.ColWidths[1]:=StringGrid1.ClientWidth - StringGrid1.ColWidths[0]-5; panel1.Parent:=StringGrid1; panel1.Width:=3; panel1.Top :=0; panel1.Left:=StringGrid1.ColWidths[0]-2; panel1.Height:=StringGrid1.ClientHeight; editValue.Parent:=StringGrid1; //cmbValueList.Parent:=StringGrid1; end; procedure TInsForm.FormResize(Sender: TObject); begin StringGrid1.ColWidths[1]:=StringGrid1.ClientWidth - StringGrid1.ColWidths[0]-5; panel1.Left:=StringGrid1.ColWidths[0]; //panel1.Height:=StringGrid1.ClientHeight; panel1.Height:=StringGrid1.RowCount * 21; end; procedure TInsForm.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if Panel1.tag<>0 then begin x:=Panel1.left + x; if x<30 then x:=30; if x>StringGrid1.width-30 then x:=StringGrid1.width-30; Panel1.left:=x; StringGrid1.ColWidths[0]:=panel1.Left; FormResize(panel1); end; end; procedure TInsForm.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Button=mbLeft then begin Panel1.tag:=Panel1.left; end; end; procedure TInsForm.Panel1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Button=mbLeft then begin Panel1.tag:=0; StringGrid1.Invalidate; end; end; procedure TInsForm.FormDestroy(Sender: TObject); begin //ContSelList.Free; end; procedure TInsForm.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var s:String; CT: TControl; r: PTypeData; m: integer; PT: TPoint; begin if (ARow=StringGrid1.Row) and (ACol=1) and (Foo=False) then begin s:=Trim(StringGrid1.Cells[0,StringGrid1.Row]); if Copy(s,1,1)='+' then s:=Copy(s,2,Length(s)-1); pinf:=GetPropInfo(C,s); if pinf.PropType^.Kind = tkEnumeration then begin cmbValueList.Clear; r:= GetTypeData(Pinf.PropType^); for m:=r.MinValue to r.MaxValue do begin cmbValueList.Items.Add(GetEnumName(Pinf.PropType^,ord(m))); end; cmbValueList.ItemIndex:=cmbValueList.Items.IndexOf(Trim(StringGrid1.Cells[1,StringGrid1.Row])); CT:=cmbValueList; end else CT:=editValue; CT.Left :=Rect.Left+2; if CT is TComboBox then CT.Top :=Rect.Top + StringGrid1.Top else CT.Top :=Rect.Top; CT.Visible:=True; CT.Width:=StringGrid1.ColWidths[1]-2; if CT is TEdit then begin TEdit(CT).Text:=StringGrid1.Cells[1,StringGrid1.Row]; TEdit(CT).SetFocus; end else begin TComboBox(CT).Text:=StringGrid1.Cells[1,StringGrid1.Row]; TComboBox(CT).SetFocus; end; Foo:=True; end else begin CT.Visible:=False; Foo:=false; end; end; procedure TInsForm.cmbCompListClick(Sender: TObject); begin editValue.Visible:=False; cmbValueList.Visible:=False; Doldur; end; procedure TInsForm.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin editValue.Visible:=False; cmbValueList.Visible:=False; end; procedure TInsForm.cmbValueListDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); begin cmbValueList.Left :=StringGrid1.ColWidths[0]; cmbValueList.Width:=StringGrid1.ColWidths[1]; end; end.