Added objects (MVC) demo

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@59 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
blikblum
2007-02-19 01:16:21 +00:00
parent af76131300
commit fab62d9664
7 changed files with 1898 additions and 0 deletions

View File

@ -0,0 +1,212 @@
object fmMVCDemo: TfmMVCDemo
Left = 258
Height = 480
Top = 174
Width = 709
HorzScrollBar.Page = 708
VertScrollBar.Page = 479
ActiveControl = edCaption
Caption = 'Virtual Tree - MVC Demo written by Marian Aldenhövel'
Font.Height = -11
Font.Name = 'MS Sans Serif'
OnCreate = FormCreate
object pnlControls: TPanel
Height = 84
Top = 396
Width = 709
Align = alBottom
BevelInner = bvLowered
BevelOuter = bvNone
Caption = ' '
TabOrder = 0
object Label1: TLabel
Left = 51
Height = 14
Top = 8
Width = 42
Alignment = taRightJustify
Caption = 'Caption:'
Color = clNone
ParentColor = False
end
object Label3: TLabel
Left = 33
Height = 14
Top = 31
Width = 58
Alignment = taRightJustify
Caption = 'Subcaption:'
Color = clNone
ParentColor = False
end
object Label4: TLabel
Left = 7
Height = 14
Top = 56
Width = 88
Alignment = taRightJustify
Caption = 'Incidence (0..63):'
Color = clNone
ParentColor = False
end
object Label2: TLabel
Left = 212
Height = 92
Top = 4
Width = 186
Caption = 'Edit the current node.'#13#10#13#10'Note that you are setting data in a structure without referring to a visual component except for the information about what node currently has the focus.'
Color = clNone
ParentColor = False
WordWrap = True
end
object edCaption: TEdit
Left = 92
Height = 21
Top = 5
Width = 112
OnChange = edCaptionChange
TabOrder = 0
Text = 'edCaption'
end
object edSubcaption: TEdit
Left = 92
Height = 21
Top = 29
Width = 112
OnChange = edSubcaptionChange
TabOrder = 1
Text = 'edCaption'
end
object edIncidence: TEdit
Left = 92
Height = 21
Top = 53
Width = 59
OnChange = edIncidenceChange
OnKeyDown = nil
OnKeyPress = edIncidenceKeyPress
TabOrder = 2
Text = '0'
end
object UpDown1: TUpDown
Left = 151
Height = 21
Top = 53
Width = 15
Associate = edIncidence
Max = 63
TabOrder = 3
end
object btnAdd: TButton
Left = 429
Height = 25
Top = 4
Width = 75
BorderSpacing.InnerBorder = 4
Caption = '+ Add a child'
OnClick = btnAddClick
TabOrder = 4
end
object btnDelete: TButton
Left = 429
Height = 25
Top = 32
Width = 75
BorderSpacing.InnerBorder = 4
Caption = '- delete node'
OnClick = btnDeleteClick
TabOrder = 5
end
object cbLive: TCheckBox
Left = 618
Height = 13
Top = 9
Width = 48
Caption = 'Live!'
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
OnClick = cbLiveClick
TabOrder = 6
end
end
object ImageList1: TImageList
left = 120
top = 143
Bitmap = {
6C690500000010000000100000009C0100002F2A2058504D202A2F0A73746174
69632063686172202A677261706869635B5D203D207B0A223136203136203320
31222C0A222E2063204E6F6E65222C0A222C20632023303030303030222C0A22
2D20632023464646464646222C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E22
2C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E222C0A222E2E2E2E2E2E2E2E2E
2C2C2E2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E
2E2E2E2E2E2E2E2C2D2D2D2C2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2D2C
2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2D2C2E2E2E222C0A222E2E2E2E2E
2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E22
2C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C
2C2C2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E
2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2C2C2C2E
2E2E2E222C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E222C0A222E2E2E2E2E
2E2E2E2E2E2E2E2E2E2E2E227D0A9C0100002F2A2058504D202A2F0A73746174
69632063686172202A677261706869635B5D203D207B0A223136203136203320
31222C0A222E2063204E6F6E65222C0A222C20632023303030303030222C0A22
2D20632023303043304330222C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E22
2C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E222C0A222E2E2E2E2E2E2E2E2E
2C2C2E2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E
2E2E2E2E2E2E2E2C2D2D2D2C2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2D2C
2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2D2C2E2E2E222C0A222E2E2E2E2E
2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E22
2C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C
2C2C2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E
2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2C2C2C2E
2E2E2E222C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E222C0A222E2E2E2E2E
2E2E2E2E2E2E2E2E2E2E2E227D0A9C0100002F2A2058504D202A2F0A73746174
69632063686172202A677261706869635B5D203D207B0A223136203136203320
31222C0A222E2063204E6F6E65222C0A222C20632023303030303030222C0A22
2D20632023303043303030222C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E22
2C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E222C0A222E2E2E2E2E2E2E2E2E
2C2C2E2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E
2E2E2E2E2E2E2E2C2D2D2D2C2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2D2C
2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2D2C2E2E2E222C0A222E2E2E2E2E
2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E22
2C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C
2C2C2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E
2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2C2C2C2E
2E2E2E222C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E222C0A222E2E2E2E2E
2E2E2E2E2E2E2E2E2E2E2E227D0A9C0100002F2A2058504D202A2F0A73746174
69632063686172202A677261706869635B5D203D207B0A223136203136203320
31222C0A222E2063204E6F6E65222C0A222C20632023303030303030222C0A22
2D20632023464630303030222C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E22
2C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E222C0A222E2E2E2E2E2E2E2E2E
2C2C2E2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E
2E2E2E2E2E2E2E2C2D2D2D2C2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2D2C
2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2D2C2E2E2E222C0A222E2E2E2E2E
2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E22
2C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C
2C2C2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E
2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2C2C2C2E
2E2E2E222C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E222C0A222E2E2E2E2E
2E2E2E2E2E2E2E2E2E2E2E227D0A9C0100002F2A2058504D202A2F0A73746174
69632063686172202A677261706869635B5D203D207B0A223136203136203320
31222C0A222E2063204E6F6E65222C0A222C20632023303030303030222C0A22
2D20632023464646463030222C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E22
2C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E222C0A222E2E2E2E2E2E2E2E2E
2C2C2E2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E
2E2E2E2E2E2E2E2C2D2D2D2C2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2D2C
2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2D2C2E2E2E222C0A222E2E2E2E2E
2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E22
2C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C
2C2C2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E
2E2E2E2E2E2E2E2C2D2D2C2E2E2E2E222C0A222E2E2E2E2E2E2E2E2C2C2C2C2E
2E2E2E222C0A222E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E222C0A222E2E2E2E2E
2E2E2E2E2E2E2E2E2E2E2E227D0A
}
end
object timLive: TTimer
Enabled = False
Interval = 100
OnTimer = timLiveTimer
left = 120
top = 172
end
end

View File

@ -0,0 +1,77 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TfmMVCDemo','FORMDATA',[
'TPF0'#10'TfmMVCDemo'#9'fmMVCDemo'#4'Left'#3#2#1#6'Height'#3#224#1#3'Top'#3
+#174#0#5'Width'#3#197#2#18'HorzScrollBar.Page'#3#196#2#18'VertScrollBar.Page'
+#3#223#1#13'ActiveControl'#7#9'edCaption'#7'Caption'#6'5Virtual Tree - MVC D'
+'emo written by Marian Aldenh'#195#182'vel'#11'Font.Height'#2#245#9'Font.Nam'
+'e'#6#13'MS Sans Serif'#8'OnCreate'#7#10'FormCreate'#0#6'TPanel'#11'pnlContr'
+'ols'#6'Height'#2'T'#3'Top'#3#140#1#5'Width'#3#197#2#5'Align'#7#8'alBottom'
+#10'BevelInner'#7#9'bvLowered'#10'BevelOuter'#7#6'bvNone'#7'Caption'#6#1' '#8
+'TabOrder'#2#0#0#6'TLabel'#6'Label1'#4'Left'#2'3'#6'Height'#2#14#3'Top'#2#8#5
+'Width'#2'*'#9'Alignment'#7#14'taRightJustify'#7'Caption'#6#8'Caption:'#5'Co'
+'lor'#7#6'clNone'#11'ParentColor'#8#0#0#6'TLabel'#6'Label3'#4'Left'#2'!'#6'H'
+'eight'#2#14#3'Top'#2#31#5'Width'#2':'#9'Alignment'#7#14'taRightJustify'#7'C'
+'aption'#6#11'Subcaption:'#5'Color'#7#6'clNone'#11'ParentColor'#8#0#0#6'TLab'
+'el'#6'Label4'#4'Left'#2#7#6'Height'#2#14#3'Top'#2'8'#5'Width'#2'X'#9'Alignm'
+'ent'#7#14'taRightJustify'#7'Caption'#6#18'Incidence (0..63):'#5'Color'#7#6
+'clNone'#11'ParentColor'#8#0#0#6'TLabel'#6'Label2'#4'Left'#3#212#0#6'Height'
+#2'\'#3'Top'#2#4#5'Width'#3#186#0#7'Caption'#6#179'Edit the current node.'#13
+#10#13#10'Note that you are setting data in a structure without referring to'
+' a visual component except for the information about what node currently ha'
+'s the focus.'#5'Color'#7#6'clNone'#11'ParentColor'#8#8'WordWrap'#9#0#0#5'TE'
+'dit'#9'edCaption'#4'Left'#2'\'#6'Height'#2#21#3'Top'#2#5#5'Width'#2'p'#8'On'
+'Change'#7#15'edCaptionChange'#8'TabOrder'#2#0#4'Text'#6#9'edCaption'#0#0#5
+'TEdit'#12'edSubcaption'#4'Left'#2'\'#6'Height'#2#21#3'Top'#2#29#5'Width'#2
+'p'#8'OnChange'#7#18'edSubcaptionChange'#8'TabOrder'#2#1#4'Text'#6#9'edCapti'
+'on'#0#0#5'TEdit'#11'edIncidence'#4'Left'#2'\'#6'Height'#2#21#3'Top'#2'5'#5
+'Width'#2';'#8'OnChange'#7#17'edIncidenceChange'#9'OnKeyDown'#13#10'OnKeyPre'
+'ss'#7#19'edIncidenceKeyPress'#8'TabOrder'#2#2#4'Text'#6#1'0'#0#0#7'TUpDown'
+#7'UpDown1'#4'Left'#3#151#0#6'Height'#2#21#3'Top'#2'5'#5'Width'#2#15#9'Assoc'
+'iate'#7#11'edIncidence'#3'Max'#2'?'#8'TabOrder'#2#3#0#0#7'TButton'#6'btnAdd'
+#4'Left'#3#173#1#6'Height'#2#25#3'Top'#2#4#5'Width'#2'K'#25'BorderSpacing.In'
+'nerBorder'#2#4#7'Caption'#6#13'+ Add a child'#7'OnClick'#7#11'btnAddClick'#8
+'TabOrder'#2#4#0#0#7'TButton'#9'btnDelete'#4'Left'#3#173#1#6'Height'#2#25#3
+'Top'#2' '#5'Width'#2'K'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#13'-'
+' delete node'#7'OnClick'#7#14'btnDeleteClick'#8'TabOrder'#2#5#0#0#9'TCheckB'
+'ox'#6'cbLive'#4'Left'#3'j'#2#6'Height'#2#13#3'Top'#2#9#5'Width'#2'0'#7'Capt'
+'ion'#6#5'Live!'#11'Font.Height'#2#245#9'Font.Name'#6#13'MS Sans Serif'#10'F'
+'ont.Style'#11#6'fsBold'#0#7'OnClick'#7#11'cbLiveClick'#8'TabOrder'#2#6#0#0#0
+#10'TImageList'#10'ImageList1'#4'left'#2'x'#3'top'#3#143#0#6'Bitmap'#10'.'#8
+#0#0'li'#5#0#0#0#16#0#0#0#16#0#0#0#156#1#0#0'/* XPM */'#10'static char *grap'
+'hic[] = {'#10'"16 16 3 1",'#10'". c None",'#10'", c #000000",'#10'"- c #FFF'
+'FFF",'#10'"................",'#10'"................",'#10'".........,,.....'
+'",'#10'"........,--,....",'#10'"........,---,...",'#10'"........,---,...",'
+#10'"........,---,...",'#10'"........,--,....",'#10'"........,--,....",'#10
+'"........,--,....",'#10'"........,,,,....",'#10'"........,--,....",'#10'"..'
+'......,--,....",'#10'"........,,,,....",'#10'"................",'#10'".....'
+'..........."}'#10#156#1#0#0'/* XPM */'#10'static char *graphic[] = {'#10'"1'
+'6 16 3 1",'#10'". c None",'#10'", c #000000",'#10'"- c #00C0C0",'#10'".....'
+'...........",'#10'"................",'#10'".........,,.....",'#10'"........'
+',--,....",'#10'"........,---,...",'#10'"........,---,...",'#10'"........,--'
+'-,...",'#10'"........,--,....",'#10'"........,--,....",'#10'"........,--,..'
+'..",'#10'"........,,,,....",'#10'"........,--,....",'#10'"........,--,...."'
+','#10'"........,,,,....",'#10'"................",'#10'"................"}'
+#10#156#1#0#0'/* XPM */'#10'static char *graphic[] = {'#10'"16 16 3 1",'#10
+'". c None",'#10'", c #000000",'#10'"- c #00C000",'#10'"................",'
+#10'"................",'#10'".........,,.....",'#10'"........,--,....",'#10
+'"........,---,...",'#10'"........,---,...",'#10'"........,---,...",'#10'"..'
+'......,--,....",'#10'"........,--,....",'#10'"........,--,....",'#10'".....'
+'...,,,,....",'#10'"........,--,....",'#10'"........,--,....",'#10'"........'
+',,,,....",'#10'"................",'#10'"................"}'#10#156#1#0#0'/*'
+' XPM */'#10'static char *graphic[] = {'#10'"16 16 3 1",'#10'". c None",'#10
+'", c #000000",'#10'"- c #FF0000",'#10'"................",'#10'"............'
+'....",'#10'".........,,.....",'#10'"........,--,....",'#10'"........,---,..'
+'.",'#10'"........,---,...",'#10'"........,---,...",'#10'"........,--,....",'
+#10'"........,--,....",'#10'"........,--,....",'#10'"........,,,,....",'#10
+'"........,--,....",'#10'"........,--,....",'#10'"........,,,,....",'#10'"..'
,'..............",'#10'"................"}'#10#156#1#0#0'/* XPM */'#10'static'
+' char *graphic[] = {'#10'"16 16 3 1",'#10'". c None",'#10'", c #000000",'#10
+'"- c #FFFF00",'#10'"................",'#10'"................",'#10'".......'
+'..,,.....",'#10'"........,--,....",'#10'"........,---,...",'#10'"........,-'
+'--,...",'#10'"........,---,...",'#10'"........,--,....",'#10'"........,--,.'
+'...",'#10'"........,--,....",'#10'"........,,,,....",'#10'"........,--,....'
+'",'#10'"........,--,....",'#10'"........,,,,....",'#10'"................",'
+#10'"................"}'#10#0#0#6'TTimer'#7'timLive'#7'Enabled'#8#8'Interval'
+#2'd'#7'OnTimer'#7#12'timLiveTimer'#4'left'#2'x'#3'top'#3#172#0#0#0#0
]);

View File

@ -0,0 +1,215 @@
unit MVCDemoMain;
{$MODE Delphi}
{ (c) 2000 Marian Aldenh�vel
Hainstra�e 8
53121 Bonn
+49 228 6203366
Fax: +49 228 624031
marian@mba-software.de
Free: You may use this code in every way you find it useful or fun.
Main form for the MVCDemo-Project. See MVCTypes.pas for Details. }
interface
uses LCLIntf,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,
MVCTypes,MVCPanel,StdCtrls,ExtCtrls,ImgList,VirtualTrees,ComCtrls,
Buttons, LResources;
type TfmMVCDemo=class(TForm)
pnlControls:TPanel;
ImageList1:TImageList;
edCaption:TEdit;
Label1:TLabel;
Label2:TLabel;
edSubcaption:TEdit;
Label3:TLabel;
edIncidence: TEdit;
Label4: TLabel;
UpDown1: TUpDown;
btnAdd: TButton;
btnDelete: TButton;
cbLive: TCheckBox;
timLive: TTimer;
procedure FormCreate(Sender:TObject);
procedure edCaptionChange(Sender:TObject);
procedure TreeViewChange(Sender:TBaseVirtualTree;Node:PVirtualNode);
procedure edIncidenceKeyPress(Sender:TObject;var Key:Char);
procedure edSubcaptionChange(Sender:TObject);
procedure edIncidenceChange(Sender:TObject);
procedure btnAddClick(Sender:TObject);
procedure btnDeleteClick(Sender: TObject);
procedure cbLiveClick(Sender: TObject);
procedure timLiveTimer(Sender: TObject);
private
P:TMVCPanel;
FTree:TMVCTree;
procedure UpdateFromNode;
function FocusedNode:TMVCNode;
function CreateDefaultTree:TMVCTree;
end;
var fmMVCDemo:TfmMVCDemo;
implementation
function TfmMVCDemo.CreateDefaultTree:TMVCTree;
{ recurse and curse :-) }
var i,j,k:integer;
begin
Result:=TMVCTree.Create;
for i:=0 to 2 do
with Result.Root.CreateChild do
begin
Caption:='Root';
SubCaption:='Number '+IntToStr(i);
Incidence:=5+random(30);
for j:=0 to 2 do
with CreateChild do
begin
Caption:='Child';
SubCaption:='Number '+IntToStr(j);
Incidence:=random(64);
for k:=0 to 1 do
with CreateChild do
begin
Caption:='Grandchild';
SubCaption:='Number '+IntToStr(k);
Incidence:=random(64);
end;
end;
end;
end;
procedure TfmMVCDemo.FormCreate(Sender: TObject);
begin
P:=TMVCPanel.Create(Self);
with P do
begin
Parent:=Self;
Align:=alClient;
TreeView.Images:=ImageList1;
{ Now this is what it's all about:
You have a structure - represented here by a call that creates
a tree. All you do is assign it to a property of the Viewer,
bingo. }
FTree:=CreateDefaultTree;
Tree:=FTree;
P.TreeView.OnChange:=TreeViewChange;
P.TreeView.FullExpand(NIL);
UpdateFromNode;
end;
end;
procedure TfmMVCDemo.TreeViewChange(Sender:TBaseVirtualTree;Node:PVirtualNode);
begin
UpdateFromNode;
end;
procedure TfmMVCDemo.UpdateFromNode;
begin
if FocusedNode=NIL
then
begin
edCaption.Text:= '';
edCaption.Enabled:= False;
edSubCaption.Text:= '';
edSubCaption.Enabled:=False;
edIncidence.Text:= '';
edIncidence.Enabled:= False;
btnDelete.Enabled:=False;
end
else
begin
edCaption.Text:= FocusedNode.Caption;
edCaption.Enabled:= True;
edSubCaption.Text:= FocusedNode.SubCaption;
edSubCaption.Enabled:=True;
edIncidence.Text:= IntToStr(FocusedNode.Incidence);
edIncidence.Enabled:= True;
btnDelete.Enabled:= True;
end;
end;
function TfmMVCDemo.FocusedNode:TMVCNode;
begin
with P.TreeView do
if FocusedNode<>NIL
then Result:=MVCNode[FocusedNode]
else Result:=NIL;
end;
procedure TfmMVCDemo.edIncidenceKeyPress(Sender:TObject;var Key:Char);
begin
if not(Key in ['0'..'9',#8]) then Key:=#0;
end;
procedure TfmMVCDemo.edSubcaptionChange(Sender:TObject);
begin
if FocusedNode<>NIL
then FocusedNode.SubCaption:=edSubCaption.Text;
end;
procedure TfmMVCDemo.edCaptionChange(Sender:TObject);
begin
if FocusedNode<>NIL then FocusedNode.Caption:=edCaption.Text;
end;
procedure TfmMVCDemo.edIncidenceChange(Sender:TObject);
begin
try
if FocusedNode<>NIL then
if edIncidence.Text=''
then FocusedNode.Incidence:=0
else FocusedNode.Incidence:=StrToInt(edIncidence.Text);
except
ShowMessage('Enter a number between 0 and 63');
end;
end;
procedure TfmMVCDemo.btnAddClick(Sender:TObject);
var R:TMVCNode;
begin
if FocusedNode<>NIL
then R:=FocusedNode
else R:=FTree.Root;
with R do
begin
R:=CreateChild;
R.Caption:='New';
end;
end;
procedure TfmMVCDemo.btnDeleteClick(Sender: TObject);
begin
FocusedNode.Free;
end;
procedure TfmMVCDemo.cbLiveClick(Sender: TObject);
begin
timLive.Enabled:=cbLive.Checked;
end;
procedure TfmMVCDemo.timLiveTimer(Sender: TObject);
var N:TMVCNode;
begin
{ Change the Incidence-Field of one node on every
level in one branch of the tree. }
N:=FTree.Root;
while Assigned(N) do
begin
N.Incidence:=5+random(63);
if N.ChildCount>0
then N:=N.Child[random(N.ChildCount)]
else N:=NIL;
end;
end;
initialization
{$i MVCDemoMain.lrs}
Randomize;
end.

View File

@ -0,0 +1,127 @@
unit MVCPanel;
{$MODE Delphi}
{ (c) 2000 Marian Aldenh�vel
Hainstra�e 8
53121 Bonn
+49 228 6203366
Fax: +49 228 624031
marian@mba-software.de
Free: You may use this code in every way you find it useful or fun.
This declares a Panel that hold another Panel and a TMVCTreeView. In
this Application is not at all useful, you could just as well create the
components at designtime.
The reason why the component is here is because it hints at the
possibility to use a TMVCTreeView in a hypothetical compound component
TMVMTreeEditor that adds more controls that modify the same structure.
It also shows how to initialize the Columns of a runtime-created
TVirtualTree.
}
interface
uses LCLIntf,Controls,Graphics,SysUtils,Classes,ExtCtrls,StdCtrls,
MVCTypes,VirtualTrees;
type TMVCPanel=class(TCustomPanel)
private
FpnlTop:TPanel;
FTrvItems:TMVCTreeView;
procedure SetItems(aTree:TMVCTree);
function GetItems:TMVCTree;
protected
procedure CreateWnd; override;
public
constructor Create(aOwner:TComponent); override;
property TreeView:TMVCTreeView read FtrvItems;
property Tree:TMVCTree read GetItems write SetItems;
end;
implementation
procedure TMVCPanel.SetItems(aTree:TMVCTree);
begin
{ Just link the Items to the TreeView, no processing of our own. }
FtrvItems.Tree:=aTree;
end;
function TMVCPanel.GetItems:TMVCTree;
begin
Result:=FtrvItems.Tree;
end;
constructor TMVCPanel.Create(aOwner:TComponent);
begin
inherited Create(aOwner);
BevelOuter:=bvNone;
Caption:=' ';
FpnlTop:=TPanel.Create(Self);
with FpnlTop do
begin
Parent:=Self;
Align:=alTop;
Height:=30;
Caption:='SomePanel';
BevelOuter:=bvNone;
BevelInner:=bvLowered;
end;
FtrvItems:=TMVCTreeView.Create(Self);
with FtrvItems do
begin
Parent:=Self;
Align:=alClient;
end;
end;
procedure TMVCPanel.CreateWnd;
begin
inherited CreateWnd;
with FtrvItems, TreeOptions do
begin
PaintOptions:=PaintOptions+[toShowButtons, // display collapse/expand
toShowHorzGridLines, // display horizontal lines
toShowRoot, // show lines also at root level
toShowTreeLines, // display tree lines to show
// hierarchy of nodes
// buttons left to a node
toShowVertGridLines]; // display vertical lines
// (depending on columns) to
// simulate a grid
MiscOptions := MiscOptions+[toEditable];
SelectionOptions := SelectionOptions+[toExtendedFocus];
// to simulate a grid
with Header do
begin
Height:=18;
Options:=Options+[hoVisible];
Background:=clBtnFace;
AutoSize:=True;
with Columns.Add do
begin
Text:='Caption';
Width:=300;
end;
with Columns.Add do
begin
Text:='SubCaption';
Width:=100;
end;
with Columns.Add do
begin
Text:='Incidence';
Width:=100;
end;
end;
end;
end;
end.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,208 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<PathDelim Value="\"/>
<Version Value="5"/>
<General>
<MainUnit Value="0"/>
<IconPath Value="./"/>
<TargetFileExt Value=".exe"/>
<ActiveEditorIndexAtStart Value="7"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
</VersionInfo>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<RequiredPackages Count="3">
<Item1>
<PackageName Value="virtualtreeview_package"/>
</Item1>
<Item2>
<PackageName Value="miscutils_package"/>
</Item2>
<Item3>
<PackageName Value="LCL"/>
</Item3>
</RequiredPackages>
<Units Count="13">
<Unit0>
<Filename Value="mvcdemo.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="mvcdemo"/>
<CursorPos X="63" Y="18"/>
<TopLine Value="1"/>
<EditorIndex Value="7"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
<Filename Value="fmain.pas"/>
<ComponentName Value="Form1"/>
<ResourceFilename Value="fmain.lrs"/>
<UnitName Value="fmain"/>
<CursorPos X="9" Y="5"/>
<TopLine Value="1"/>
<UsageCount Value="20"/>
</Unit1>
<Unit2>
<Filename Value="MVCDemoMain.pas"/>
<ComponentName Value="fmMVCDemo"/>
<HasResources Value="True"/>
<IsPartOfProject Value="True"/>
<ResourceFilename Value="MVCDemoMain.lrs"/>
<UnitName Value="MVCDemoMain"/>
<CursorPos X="9" Y="16"/>
<TopLine Value="57"/>
<EditorIndex Value="0"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit2>
<Unit3>
<Filename Value="MVCPanel.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="MVCPanel"/>
<CursorPos X="18" Y="79"/>
<TopLine Value="69"/>
<EditorIndex Value="2"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
<Filename Value="MVCTypes.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="MVCTypes"/>
<CursorPos X="26" Y="1"/>
<TopLine Value="1"/>
<EditorIndex Value="3"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit4>
<Unit5>
<Filename Value="..\..\VirtualTrees.pas"/>
<UnitName Value="VirtualTrees"/>
<CursorPos X="5" Y="17913"/>
<TopLine Value="17896"/>
<EditorIndex Value="8"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit5>
<Unit6>
<Filename Value="..\..\..\luipack\trunk\miscutils\delphicompat.pas"/>
<UnitName Value="delphicompat"/>
<CursorPos X="31" Y="39"/>
<TopLine Value="28"/>
<EditorIndex Value="6"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit6>
<Unit7>
<Filename Value="..\..\..\lazarus\lcl\controls.pp"/>
<UnitName Value="Controls"/>
<CursorPos X="50" Y="1542"/>
<TopLine Value="1525"/>
<EditorIndex Value="4"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit7>
<Unit8>
<Filename Value="..\..\..\lazarus\lcl\lcltype.pp"/>
<UnitName Value="LCLType"/>
<CursorPos X="3" Y="2043"/>
<TopLine Value="2026"/>
<EditorIndex Value="5"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit8>
<Unit9>
<Filename Value="..\..\VTConfig.inc"/>
<CursorPos X="3" Y="32"/>
<TopLine Value="1"/>
<EditorIndex Value="11"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit9>
<Unit10>
<Filename Value="..\..\..\lazarus\lcl\interfaces\win32\win32callback.inc"/>
<CursorPos X="34" Y="940"/>
<TopLine Value="922"/>
<EditorIndex Value="10"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit10>
<Unit11>
<Filename Value="..\..\port.log"/>
<CursorPos X="51" Y="172"/>
<TopLine Value="153"/>
<EditorIndex Value="9"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
<SyntaxHighlighter Value="None"/>
</Unit11>
<Unit12>
<Filename Value="..\..\..\luipack\trunk\multilog\multiloglcl.pas"/>
<UnitName Value="multiloglcl"/>
<CursorPos X="4" Y="91"/>
<TopLine Value="67"/>
<EditorIndex Value="1"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit12>
</Units>
<JumpHistory Count="4" HistoryIndex="3">
<Position1>
<Filename Value="..\..\..\luipack\trunk\multilog\multiloglcl.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
</Position1>
<Position2>
<Filename Value="..\..\..\luipack\trunk\multilog\multiloglcl.pas"/>
<Caret Line="47" Column="15" TopLine="30"/>
</Position2>
<Position3>
<Filename Value="..\..\VirtualTrees.pas"/>
<Caret Line="17911" Column="39" TopLine="17880"/>
</Position3>
<Position4>
<Filename Value="..\..\VTConfig.inc"/>
<Caret Line="32" Column="3" TopLine="1"/>
</Position4>
</JumpHistory>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>
<PathDelim Value="\"/>
<CodeGeneration>
<Generate Value="Faster"/>
</CodeGeneration>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="2">
<Item1>
<Name Value="ECodetoolError"/>
</Item1>
<Item2>
<Name Value="EFOpenError"/>
</Item2>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,18 @@
program mvcdemo;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms
{ add your units here }, MVCDemoMain;
begin
Application.Initialize;
Application.CreateForm(TfmMVCDemo, fmMVCDemo);
Application.Run;
end.