jvcllaz: Add new component TDBLookupTreeView with demo.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6870 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2019-04-27 17:15:09 +00:00
parent 0d39fd7dfd
commit 0bd361c6e9
20 changed files with 2228 additions and 16 deletions

View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="JvDBLookupTreeViewDemo"/>
<Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
<Icon Value="0"/>
</General>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<RequiredPackages Count="3">
<Item1>
<PackageName Value="JvDBLazR"/>
</Item1>
<Item2>
<PackageName Value="FCL"/>
</Item2>
<Item3>
<PackageName Value="LCL"/>
</Item3>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="JvDBLookupTreeViewDemo.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="main.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="..\..\bin\JvDBLookupTreeViewDemo"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
</CONFIG>

View File

@ -0,0 +1,22 @@
program JvDBLookupTreeViewDemo;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, main
{ you can add units after this };
{$R *.res}
begin
RequireDerivedFormResource := True;
Application.Scaled := True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@ -0,0 +1,176 @@
object Form1: TForm1
Left = 374
Height = 477
Top = 164
Width = 594
Caption = 'JvDBLookup controls'
ClientHeight = 477
ClientWidth = 594
OnShow = FormShow
LCLVersion = '2.1.0.0'
object JvDBLookupTreeView1: TJvDBLookupTreeView
AnchorSideLeft.Control = Bevel1
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 307
Height = 349
Top = 112
Width = 271
BorderSpacing.Right = 16
BorderSpacing.Bottom = 16
DataField = 'ID'
DataSource = DSPersons
KeyField = 'RelID'
ListField = 'RelName'
ListSource = DSRelationships
TabOrder = 0
Anchors = [akTop, akLeft, akRight, akBottom]
MasterField = 'RelID'
DetailField = 'RelParentID'
StartMasterValue = '0'
Indent = 15
end
object Label2: TLabel
AnchorSideTop.Control = DBNavigator1
AnchorSideTop.Side = asrBottom
Left = 16
Height = 15
Top = 92
Width = 39
BorderSpacing.Top = 16
Caption = 'Person:'
ParentColor = False
end
object DBNavigator1: TDBNavigator
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrBottom
Left = 16
Height = 26
Top = 50
Width = 241
BevelOuter = bvNone
BorderSpacing.Left = 16
BorderSpacing.Top = 16
ChildSizing.EnlargeHorizontal = crsScaleChilds
ChildSizing.EnlargeVertical = crsScaleChilds
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 100
ClientHeight = 26
ClientWidth = 241
DataSource = DSPersons
Options = []
TabOrder = 1
end
object Label3: TLabel
AnchorSideLeft.Control = Bevel1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label2
Left = 307
Height = 15
Top = 92
Width = 146
Caption = 'Relationship to protagonist:'
ParentColor = False
end
object Panel1: TPanel
Left = 0
Height = 34
Top = 0
Width = 594
Align = alTop
Caption = '(Some) persons in the novel "The Grapes of Wrath" by John Steinbeck'
Color = clBackground
Font.Color = clHighlightText
Font.Height = -16
Font.Style = [fsBold]
ParentColor = False
ParentFont = False
TabOrder = 2
end
object DBGrid1: TDBGrid
AnchorSideLeft.Control = DBNavigator1
AnchorSideTop.Control = Label2
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Bevel1
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 16
Height = 350
Top = 111
Width = 271
Anchors = [akTop, akLeft, akRight, akBottom]
AutoFillColumns = True
BorderSpacing.Top = 4
BorderSpacing.Bottom = 16
Color = clWindow
Columns = <
item
Title.Caption = 'Name'
Width = 238
FieldName = 'Name'
end>
DataSource = DSPersons
TabOrder = 3
OnPrepareCanvas = DBGrid1PrepareCanvas
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
Left = 287
Height = 50
Top = 78
Width = 20
Shape = bsSpacer
end
object Persons: TBufDataset
FieldDefs = <
item
Name = 'ID'
DataType = ftInteger
end
item
Name = 'Name'
DataType = ftString
Size = 30
end>
left = 80
top = 160
end
object Relationships: TBufDataset
FieldDefs = <
item
Name = 'RelID'
DataType = ftInteger
end
item
Name = 'RelName'
DataType = ftString
Size = 30
end
item
Name = 'RelParentID'
DataType = ftString
Size = 16
end>
left = 424
top = 160
end
object DSPersons: TDataSource
AutoEdit = False
DataSet = Persons
left = 80
top = 224
end
object DSRelationships: TDataSource
AutoEdit = False
DataSet = Relationships
left = 424
top = 224
end
end

View File

@ -0,0 +1,111 @@
unit main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, BufDataset, DB, Forms, Controls, Graphics, Dialogs,
DBGrids, JvDBLookup, JvDBLookupTreeView, JvDBTreeView, ExtCtrls, DBCtrls,
StdCtrls, Grids;
type
{ TForm1 }
TForm1 = class(TForm)
Bevel1: TBevel;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
Label2: TLabel;
Label3: TLabel;
Panel1: TPanel;
JvDBLookupTreeView1: TJvDBLookupTreeView;
Persons: TBufDataset;
Relationships: TBufDataset;
DSPersons: TDataSource;
DSRelationships: TDataSource;
procedure DBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;
Column: TColumn; AState: TGridDrawState);
procedure FormShow(Sender: TObject);
private
public
Image: TImage;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
{ Assignment of table fields to lookup tree
Table "Persons" --> Master table
Table "Relationships" --> Lookup table
Establish the tree for lookup table:
DSRelationships --> LookupTreeView.ListSource
Field "RelID" --> LookuptreeView.MasterField
Field "RelParentID" --> LookupTreeView.DetailField
Field "RelName" --> LookupTreeView.ListField // Node text
Establish lookup connection:
DSPersons --> LookupTreeView.Datasource
Field "ID" --> LookupTreeView.DataField
Field "RelID" --> LookupTreeView.KeyField
}
procedure TForm1.FormShow(Sender: TObject);
begin
Relationships.CreateDataset;
Relationships.Open;
Relationships.AppendRecord([ 1, 'Grandparents', 0]);
Relationships.AppendRecord([10, 'Parents', 1]);
Relationships.AppendRecord([11, 'Uncle', 1]);
Relationships.AppendRecord([12, 'Aunt', 1]);
Relationships.AppendRecord([20, 'Protagonist', 10]);
Relationships.AppendRecord([21, 'Brother', 10]);
Relationships.AppendRecord([22, 'Sister', 10]);
Relationships.AppendRecord([23, 'Brother-in-law', 21]);
Relationships.AppendRecord([24, 'Brother-in-law', 22]);
Relationships.AppendRecord([25, 'Sister-in-law', 21]);
Relationships.AppendRecord([26, 'Sister-in-law', 22]);
Relationships.AppendRecord([30, 'Son', 20]);
Relationships.AppendRecord([31, 'Daughter', 20]);
Relationships.AppendRecord([90, 'Friend', 0]);
Relationships.AppendRecord([91, 'Neighbor', 0]);
// data from: https://en.wikipedia.org/wiki/The_Grapes_of_Wrath
Persons.CreateDataset;
Persons.Open;
Persons.AppendRecord([20, 'Tom Joad']); // Protagonist
Persons.AppendRecord([11, 'Uncle John Joad']);
Persons.Appendrecord([10, 'Ma Joad']); // name not mentioned
Persons.AppendRecord([10, 'Tom Joad']); // Pa Joad
Persons.AppendRecord([21, 'Al Joad']);
Persons.AppendRecord([21, 'Noah Joad']);
Persons.AppendRecord([22, 'Ruthie Joad']);
Persons.AppendRecord([22, 'Winfield Joad']);
Persons.AppendRecord([22, 'Rose of Sharon Joad Rivers']);
Persons.AppendRecord([ 1, 'William James Joad']);
Persons.AppendRecord([ 1, 'Granma Joad']); // name not mentioned
Persons.AppendRecord([90, 'Jim Casy']);
Persons.AppendRecord([91, 'Muley Graves']);
Persons.AppendRecord([24, 'Connie Rivers']);
Persons.IndexFieldNames := 'Name';
Persons.First;
end;
procedure TForm1.DBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;
Column: TColumn; AState: TGridDrawState);
begin
if Persons.FieldByName('ID').AsInteger = 20 then // Protagonist
DBGrid1.Canvas.Font.Style := [fsBold];
end;
end.

View File

@ -7,7 +7,7 @@ object Form1: TForm1
ClientHeight = 509
ClientWidth = 758
OnCreate = FormCreate
LCLVersion = '1.9.0.0'
LCLVersion = '2.1.0.0'
object DBGrid1: TDBGrid
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner

View File

@ -67,6 +67,14 @@ begin
JvDBTreeView1.FullCollapse;
end;
{ Assignment of table fields to tree
Table Tree
ID --> Tree.MasterField
ParentID --> Tree.DetailField
Name --> Tree.itemField
Icon --> Tree.IconField
}
procedure TForm1.FormCreate(Sender: TObject);
procedure AddRecord(ID, ParentID: Integer; AName: String; AIcon: Integer = -1);