Skip to content

Commit

Permalink
Enh: Classes grid cells now show details when selected
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveBlakeman64 committed Apr 10, 2021
1 parent b8b7c92 commit a555915
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Tests/Tests.dproj.local
*.stat
*.identcache
*.dsk
__recovery
29 changes: 22 additions & 7 deletions DelphiClass.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ interface
Classes;

type
TDelphiClassStatType = (
dcName,
dcRoutines,
dcProperties,
dcFileName
);

TDelphiClass = class
private
fName : String;
Expand All @@ -18,19 +25,14 @@ TDelphiClass = class
constructor Create(Name: String; FileName: String);
destructor Destroy; override;

procedure GetStatDetails(StatType: TDelphiClassStatType; Strings: TStrings);

property Name : String read fName;
property FileName : String read fFileName;
property Routines : TStringList read fRoutines;
property Properties: TStringList read fProperties;
end;

TDelphiClassStatType = (
dcName,
dcRoutines,
dcProperties,
dcFileName
);

TDelphiClassComparer = class(TComparer<TDelphiClass>)
private
fSortCol: TDelphiClassStatType;
Expand Down Expand Up @@ -62,6 +64,19 @@ destructor TDelphiClass.Destroy;
inherited;
end;

procedure TDelphiClass.GetStatDetails(StatType: TDelphiClassStatType; Strings: TStrings);
begin
Strings.Clear;
case StatType of
dcName : Strings.AddObject(Name, Self);
dcFileName : Strings.AddObject(FileName, Self);
dcRoutines : Strings.Assign(fRoutines);
dcProperties : Strings.Assign(fProperties);
else
raise Exception.Create('TDelphiClass.GetStatDetails: unknown stat type');
end
end;

{ TDelphiClassComparer }

function TDelphiClassComparer.Compare(const Left, Right: TDelphiClass): Integer;
Expand Down
4 changes: 2 additions & 2 deletions Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ object FormMain: TFormMain
TabOrder = 1
OnDrawCell = StringGridClassesDrawCell
OnMouseDown = StringGridClassesMouseDown
OnSelectCell = StringGridStatsSelectCell
OnSelectCell = StringGridClassesSelectCell
ExplicitLeft = 1
ExplicitTop = 36
ExplicitWidth = 832
ExplicitHeight = 398
end
object ListBox1: TListBox
object ListBoxClassDetails: TListBox
Left = 0
Top = 438
Width = 834
Expand Down
21 changes: 20 additions & 1 deletion Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ TFormMain = class(TForm)
Panel3: TPanel;
LabelClasses: TLabel;
StringGridClasses: TStringGrid;
ListBox1: TListBox;
ListBoxClassDetails: TListBox;
procedure Exit1Click(Sender: TObject);
procedure Open1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
Expand All @@ -89,6 +89,8 @@ TFormMain = class(TForm)
Rect: TRect; State: TGridDrawState);
procedure StringGridClassesMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure StringGridClassesSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
private
fProject: TDelphiProject;
procedure CheckControls;
Expand Down Expand Up @@ -569,6 +571,23 @@ procedure TFormMain.StringGridClassesMouseDown(Sender: TObject;
end
end;

procedure TFormMain.StringGridClassesSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var
SelectedClass: TDelphiClass;
begin
if (ARow > 0) then
begin
if StringGridClasses.Objects[0, ARow] is TDelphiClass then
begin
SelectedClass:=StringGridClasses.Objects[0, ARow] as TDelphiClass;
SelectedClass.GetStatDetails(ClassStatTypeForCol(ACol), ListBoxClassDetails.Items);
end
else
ListBoxClassDetails.Clear;
end
end;

procedure TFormMain.StringGridStatsDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var
SaveBrush: TBrushRecall;
Expand Down

0 comments on commit a555915

Please sign in to comment.