├── .gitattributes ├── .gitignore ├── 01_Basics ├── 01_Console101 │ ├── Console101.dpr │ ├── Console101.dproj │ ├── Console101.res │ └── Unit1.pas ├── 02_Visual01 │ ├── Visual01.dpr │ ├── Visual01.dproj │ ├── Visual01.res │ ├── Visual01Form.fmx │ └── Visual01Form.pas ├── 03_IntegersTest │ ├── IntegersTest.dpr │ ├── IntegersTest.dproj │ ├── IntegersTest.res │ ├── IntegersTestForm.fmx │ └── IntegersTestForm.pas ├── 04_CharsTest │ ├── CharsTest.dpr │ ├── CharsTest.dproj │ ├── CharsTest.res │ ├── CharsTestForm.fmx │ └── CharsTestForm.pas ├── 05_UserTypes │ ├── UserTypes.dpr │ ├── UserTypes.dproj │ ├── UserTypes.res │ ├── UserTypesForm.fmx │ └── UserTypesForm.pas ├── 06_IfTest │ ├── IfTest.dpr │ ├── IfTest.dproj │ ├── IfTest.res │ ├── IfTestForm.fmx │ └── IfTestForm.pas ├── 07_ForTest │ ├── ForTest.dpr │ ├── ForTest.dproj │ ├── ForTest.res │ ├── ForTestForm.fmx │ └── ForTestForm.pas ├── 08_OverloadTest │ ├── OverloadTest.dpr │ ├── OverloadTest.dproj │ ├── OverloadTest.res │ ├── OverloadTestForm.fmx │ └── OverloadTestForm.pas ├── 09_RecordMethods │ ├── RecordMethods.dpr │ ├── RecordMethods.dproj │ ├── RecordMethods.res │ ├── RecordMethodsForm.fmx │ └── RecordMethodsForm.pas ├── 10_OperatorsOver │ ├── OperatorsOver.dpr │ ├── OperatorsOver.dproj │ ├── OperatorsOver.res │ ├── OperatorsOverForm.fmx │ ├── OperatorsOverForm.pas │ └── OperatorsTypes.pas ├── 11_StringHelperTest │ ├── StringHelperForm.fmx │ ├── StringHelperForm.pas │ ├── StringHelperTest.dpr │ ├── StringHelperTest.dproj │ └── StringHelperTest.res ├── 12_StringMetaTest │ ├── StringMetaTest.dpr │ ├── StringMetaTest.dproj │ ├── StringMetaTest.res │ ├── StringMetaTestForm.fmx │ └── StringMetaTestForm.pas ├── 13_PointersTest │ ├── PointersTest.dpr │ ├── PointersTest.dproj │ ├── PointersTest.res │ ├── PointersTestForm.fmx │ └── PointersTestForm.pas └── ProjectGroup1.groupproj ├── 02_OOP ├── 01_Dates4 │ ├── Dates4.dpr │ ├── Dates4.dproj │ ├── Dates4.res │ ├── DatesForm.fmx │ └── DatesForm.pas ├── 02_ClicksCount │ ├── ClicksCount.dpr │ ├── ClicksCount.dproj │ ├── ClicksCount.res │ ├── ClicksCountForm.fmx │ └── ClicksCountForm.pas ├── 03_DerivedDates │ ├── Dates.pas │ ├── DerivedDates.dpr │ ├── DerivedDates.dproj │ ├── DerivedDates.res │ ├── ViewDatesForm.fmx │ └── ViewDatesForm.pas ├── 04_ControlHelper │ ├── ControlHelper.dpr │ ├── ControlHelper.dproj │ ├── ControlHelper.res │ ├── HelperForm.fmx │ └── HelperForm.pas ├── 05_FormProperties │ ├── FormProperties.dpr │ ├── FormProperties.dproj │ ├── FormProperties.res │ ├── FormPropertiesForm.fmx │ └── FormPropertiesForm.pas ├── 06_DynamicEvents │ ├── DynamicEvents.dpr │ ├── DynamicEvents.dproj │ ├── DynamicEvents.res │ ├── DynamicEventsForm.fmx │ └── DynamicEventsForm.pas ├── 07_ClassRef │ ├── ClassRef.dpr │ ├── ClassRef.dproj │ ├── ClassRef.res │ ├── ClassRefForm.fmx │ └── ClassRefForm.pas ├── 08_Intf101 │ ├── InterfaceForm.fmx │ ├── InterfaceForm.pas │ ├── Intf101.dpr │ ├── Intf101.dproj │ └── Intf101.res ├── 09_IntfDemo │ ├── InterfaceForm.fmx │ ├── InterfaceForm.pas │ ├── IntfDemo.dpr │ ├── IntfDemo.dproj │ └── IntfDemo.res ├── 10_AdapterIntf_VCL │ ├── Adapter_Demo.dpr │ ├── Adapter_Demo.dproj │ ├── Adapter_Demo.res │ ├── IEdit.pas │ ├── ILabel.pas │ ├── IProgressBar.pas │ ├── adapter_intf.pas │ ├── mainform.dfm │ └── mainform.pas ├── 11_ExceptionFinally │ ├── ExceptFinally.dpr │ ├── ExceptFinally.dproj │ ├── ExceptFinally.res │ ├── ExceptionForm.fmx │ └── ExceptionForm.pas └── ProjectGroup2.groupproj ├── 03_Modern ├── 01_KeyValueGeneric_VCL │ ├── KeyValueCode.pas │ ├── KeyValueForm.dfm │ ├── KeyValueForm.pas │ ├── KeyValueGeneric.dpr │ ├── KeyValueGeneric.dproj │ └── KeyValueGeneric.res ├── 02_StringListVsDictionary_VCL │ ├── ListDictionary_MainForm.dfm │ ├── ListDictionary_MainForm.pas │ ├── StringListVsDictionary.dpr │ ├── StringListVsDictionary.dproj │ └── StringListVsDictionary.res ├── 03_GenericMethod │ ├── GenericForm.fmx │ ├── GenericForm.pas │ ├── GenericMethod.dpr │ ├── GenericMethod.dproj │ └── GenericMethod.res ├── 04_RttiAccess │ ├── RttiAccess.dpr │ ├── RttiAccess.dproj │ ├── RttiAccess.res │ ├── RttiForm.fmx │ └── RttiForm.pas ├── 05_TypesList │ ├── TypeInfoForm.fmx │ ├── TypeInfoForm.pas │ ├── TypesForm.fmx │ ├── TypesForm.pas │ ├── TypesList.dpr │ ├── TypesList.dproj │ └── TypesList.res ├── 06_RttiAttrib_VCL │ ├── RttiAttrib.dpr │ ├── RttiAttrib.dproj │ ├── RttiAttrib.res │ ├── RttiAttribMainForm.dfm │ └── RttiAttribMainForm.pas ├── 07_DescriptionAttribute_VCL │ ├── DescriptionAttribute.dpr │ ├── DescriptionAttribute.dproj │ ├── DescriptionAttribute.res │ ├── DescriptionAttribute_Classes.pas │ ├── DescriptionAttribute_MainForm.dfm │ └── DescriptionAttribute_MainForm.pas └── ProjectGroup3.groupproj ├── 04_AnonPPL ├── 01_AnonymFirst_VCL │ ├── AnonymFirst.dpr │ ├── AnonymFirst.dproj │ ├── AnonymFirst.res │ ├── AnonymFirst_MainForm.dfm │ └── AnonymFirst_MainForm.pas ├── 02_AnonButton │ ├── AnonButton.dpr │ ├── AnonButton.dproj │ ├── AnonButton.res │ ├── AnonButtonForm.fmx │ └── AnonButtonForm.pas ├── 03_ParallelFor │ ├── AndroidManifest.template.xml │ ├── Entitlement.TemplateOSX32.xml │ ├── ParallelForGroup.groupproj │ ├── ParallelForMultiForm.fmx │ ├── ParallelForMultiForm.pas │ ├── ParallelForVCL.dpr │ ├── ParallelForVCL.dproj │ ├── ParallelFor_MainForm.dfm │ ├── ParallelFor_MainForm.pas │ ├── ParallelFor_MainForm.vlb │ ├── ParallelFormMulti.deployproj │ ├── ParallelFormMulti.dpr │ ├── ParallelFormMulti.dproj │ └── ParallelFormMulti.res ├── 04_AutoThreading │ ├── AutoThreading.dpr │ ├── AutoThreading.dproj │ ├── AutoThreading.res │ ├── AutoThreading_Icon.ico │ ├── AutoThreading_mainForm.dfm │ └── AutoThreading_mainForm.pas ├── 05_ParallelTasksAndFutures │ ├── ParallelForm.dfm │ ├── ParallelForm.pas │ ├── ParallelTaskAndFutures.dpr │ ├── ParallelTaskAndFutures.dproj │ └── ParallelTaskAndFutures.res └── ProjectGroup4.groupproj └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /01_Basics/01_Console101/Console101.dpr: -------------------------------------------------------------------------------- 1 | program Console101; 2 | 3 | {$APPTYPE CONSOLE} 4 | 5 | {$R *.res} 6 | 7 | uses 8 | System.SysUtils, 9 | Unit1 in 'Unit1.pas'; 10 | 11 | begin 12 | try 13 | Hello; 14 | readln; 15 | except 16 | on E: Exception do 17 | Writeln(E.ClassName, ': ', E.Message); 18 | end; 19 | end. 20 | -------------------------------------------------------------------------------- /01_Basics/01_Console101/Console101.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/01_Console101/Console101.res -------------------------------------------------------------------------------- /01_Basics/01_Console101/Unit1.pas: -------------------------------------------------------------------------------- 1 | unit Unit1; 2 | 3 | interface 4 | 5 | procedure Hello; 6 | 7 | implementation 8 | 9 | procedure Hello; 10 | begin 11 | writeln ('Hello, BootCamp'); 12 | end; 13 | 14 | end. 15 | -------------------------------------------------------------------------------- /01_Basics/02_Visual01/Visual01.dpr: -------------------------------------------------------------------------------- 1 | program Visual01; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | Visual01Form in 'Visual01Form.pas' {Form5}; 7 | 8 | {$R *.res} 9 | 10 | begin 11 | Application.Initialize; 12 | Application.CreateForm(TForm5, Form5); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /01_Basics/02_Visual01/Visual01.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/02_Visual01/Visual01.res -------------------------------------------------------------------------------- /01_Basics/02_Visual01/Visual01Form.fmx: -------------------------------------------------------------------------------- 1 | object Form5: TForm5 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form5' 5 | ClientHeight = 428 6 | ClientWidth = 401 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object Button1: TButton 12 | Position.X = 144.000000000000000000 13 | Position.Y = 88.000000000000000000 14 | TabOrder = 0 15 | Text = 'Button1' 16 | OnClick = Button1Click 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /01_Basics/02_Visual01/Visual01Form.pas: -------------------------------------------------------------------------------- 1 | unit Visual01Form; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, 8 | FMX.Controls.Presentation, FMX.StdCtrls; 9 | 10 | type 11 | TForm5 = class(TForm) 12 | Button1: TButton; 13 | procedure Button1Click(Sender: TObject); 14 | private 15 | { Private declarations } 16 | public 17 | { Public declarations } 18 | end; 19 | 20 | var 21 | Form5: TForm5; 22 | 23 | implementation 24 | 25 | {$R *.fmx} 26 | 27 | procedure TForm5.Button1Click(Sender: TObject); 28 | begin 29 | ShowMessage ('Hello, BootCamp'); 30 | end; 31 | 32 | end. 33 | -------------------------------------------------------------------------------- /01_Basics/03_IntegersTest/IntegersTest.dpr: -------------------------------------------------------------------------------- 1 | program IntegersTest; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | IntegersTestForm in 'IntegersTestForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /01_Basics/03_IntegersTest/IntegersTest.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/03_IntegersTest/IntegersTest.res -------------------------------------------------------------------------------- /01_Basics/03_IntegersTest/IntegersTestForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Position.X = 24.000000000000000000 15 | Position.Y = 144.000000000000000000 16 | Size.Width = 321.000000000000000000 17 | Size.Height = 393.000000000000000000 18 | Size.PlatformDefault = False 19 | TabOrder = 0 20 | Viewport.Width = 313.000000000000000000 21 | Viewport.Height = 385.000000000000000000 22 | end 23 | object Button1: TButton 24 | Position.X = 24.000000000000000000 25 | Position.Y = 16.000000000000000000 26 | Size.Width = 321.000000000000000000 27 | Size.Height = 44.000000000000000000 28 | Size.PlatformDefault = False 29 | TabOrder = 1 30 | Text = 'Integer Helper' 31 | OnClick = Button1Click 32 | end 33 | object Button2: TButton 34 | Position.X = 24.000000000000000000 35 | Position.Y = 80.000000000000000000 36 | Size.Width = 321.000000000000000000 37 | Size.Height = 44.000000000000000000 38 | Size.PlatformDefault = False 39 | TabOrder = 2 40 | Text = 'Ordinal Functions' 41 | OnClick = Button2Click 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /01_Basics/03_IntegersTest/IntegersTestForm.pas: -------------------------------------------------------------------------------- 1 | unit IntegersTestForm; 2 | 3 | interface 4 | 5 | // running this program raises an exception by design 6 | 7 | uses 8 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 9 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 10 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 11 | 12 | type 13 | TForm1 = class(TForm) 14 | Memo1: TMemo; 15 | Button1: TButton; 16 | Button2: TButton; 17 | procedure Button1Click(Sender: TObject); 18 | procedure Button2Click(Sender: TObject); 19 | private 20 | { Private declarations } 21 | public 22 | procedure Show (const msg: string); 23 | end; 24 | 25 | var 26 | Form1: TForm1; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TForm1.Button1Click(Sender: TObject); 33 | var 34 | N: Integer; 35 | begin 36 | N := 10; 37 | Show (N.ToString); 38 | 39 | // display a constant 40 | Show (33.ToString); 41 | 42 | // type operation, show the bytes required to store the type 43 | Show (Integer.Size.ToString); 44 | end; 45 | 46 | procedure TForm1.Button2Click(Sender: TObject); 47 | var 48 | n: UInt16; 49 | begin 50 | n := Low (UInt16); 51 | Inc (n); 52 | Show (IntToStr (n)); 53 | Inc (n, 10); 54 | Show (IntToStr (n)); 55 | if Odd (n) then 56 | Show (IntToStr (n) + ' is odd'); 57 | 58 | // n := 100 + High (n); 59 | // Inc (n, High (n)); 60 | Show (IntToStr (n)); 61 | end; 62 | 63 | procedure TForm1.Show(const msg: string); 64 | begin 65 | Memo1.Lines.Add(msg); 66 | end; 67 | 68 | end. 69 | -------------------------------------------------------------------------------- /01_Basics/04_CharsTest/CharsTest.dpr: -------------------------------------------------------------------------------- 1 | program CharsTest; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | CharsTestForm in 'CharsTestForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /01_Basics/04_CharsTest/CharsTest.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/04_CharsTest/CharsTest.res -------------------------------------------------------------------------------- /01_Basics/04_CharsTest/CharsTestForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Position.X = 24.000000000000000000 15 | Position.Y = 192.000000000000000000 16 | Size.Width = 353.000000000000000000 17 | Size.Height = 329.000000000000000000 18 | Size.PlatformDefault = False 19 | TabOrder = 0 20 | Viewport.Width = 345.000000000000000000 21 | Viewport.Height = 321.000000000000000000 22 | end 23 | object Button1: TButton 24 | Position.X = 24.000000000000000000 25 | Position.Y = 16.000000000000000000 26 | Size.Width = 321.000000000000000000 27 | Size.Height = 44.000000000000000000 28 | Size.PlatformDefault = False 29 | TabOrder = 1 30 | Text = 'Char Helper' 31 | OnClick = Button1Click 32 | end 33 | object Button2: TButton 34 | Position.X = 24.000000000000000000 35 | Position.Y = 80.000000000000000000 36 | Size.Width = 321.000000000000000000 37 | Size.Height = 44.000000000000000000 38 | Size.PlatformDefault = False 39 | TabOrder = 2 40 | Text = 'Ordinal Char Functions' 41 | OnClick = Button2Click 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /01_Basics/04_CharsTest/CharsTestForm.pas: -------------------------------------------------------------------------------- 1 | unit CharsTestForm; 2 | 3 | interface 4 | 5 | // running this program raises an exception by design 6 | 7 | uses 8 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 9 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 10 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 11 | 12 | type 13 | TForm1 = class(TForm) 14 | Memo1: TMemo; 15 | Button1: TButton; 16 | Button2: TButton; 17 | procedure Button1Click(Sender: TObject); 18 | procedure Button2Click(Sender: TObject); 19 | private 20 | { Private declarations } 21 | public 22 | procedure Show (const msg: string); 23 | end; 24 | 25 | var 26 | Form1: TForm1; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | uses 33 | Character; 34 | 35 | procedure TForm1.Button1Click(Sender: TObject); 36 | var 37 | ch: Char; 38 | begin 39 | ch := 'a'; 40 | Show (BoolToStr(ch.IsLetter, True)); 41 | Show (ch.ToUpper); 42 | end; 43 | 44 | procedure TForm1.Button2Click(Sender: TObject); 45 | var 46 | ch: Char; 47 | str1: string; 48 | begin 49 | ch := 'a'; 50 | Show (ch); 51 | Inc (ch, 100); 52 | Show (ch); 53 | 54 | str1 := ''; 55 | for ch := #32 to #1024 do 56 | str1 := str1 + ch; 57 | Show (str1) 58 | end; 59 | 60 | procedure TForm1.Show(const msg: string); 61 | begin 62 | Memo1.Lines.Add(msg); 63 | end; 64 | 65 | end. 66 | -------------------------------------------------------------------------------- /01_Basics/05_UserTypes/UserTypes.dpr: -------------------------------------------------------------------------------- 1 | program UserTypes; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | UserTypesForm in 'UserTypesForm.pas' {Form1}; 7 | 8 | {$R *.res} 9 | 10 | begin 11 | Application.Initialize; 12 | Application.CreateForm(TForm1, Form1); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /01_Basics/05_UserTypes/UserTypes.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/05_UserTypes/UserTypes.res -------------------------------------------------------------------------------- /01_Basics/05_UserTypes/UserTypesForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Position.X = 24.000000000000000000 15 | Position.Y = 144.000000000000000000 16 | Size.Width = 321.000000000000000000 17 | Size.Height = 393.000000000000000000 18 | Size.PlatformDefault = False 19 | TabOrder = 0 20 | Viewport.Width = 313.000000000000000000 21 | Viewport.Height = 385.000000000000000000 22 | end 23 | object Button1: TButton 24 | Position.X = 24.000000000000000000 25 | Position.Y = 16.000000000000000000 26 | Size.Width = 321.000000000000000000 27 | Size.Height = 44.000000000000000000 28 | Size.PlatformDefault = False 29 | TabOrder = 1 30 | Text = 'Button' 31 | OnClick = Button1Click 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /01_Basics/05_UserTypes/UserTypesForm.pas: -------------------------------------------------------------------------------- 1 | unit UserTypesForm; 2 | 3 | interface 4 | 5 | // running this program raises an exception by design 6 | 7 | uses 8 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 9 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 10 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 11 | 12 | type 13 | TForm1 = class(TForm) 14 | Memo1: TMemo; 15 | Button1: TButton; 16 | procedure Button1Click(Sender: TObject); 17 | private 18 | { Private declarations } 19 | public 20 | procedure Show (const msg: string); 21 | end; 22 | 23 | var 24 | Form1: TForm1; 25 | 26 | type 27 | TTen = 1..10; 28 | TUpperCase = 'A'..'Z'; 29 | TSuit = (Club, Diamond, Heart, Spade); 30 | TSuits = set of TSuit; 31 | 32 | implementation 33 | 34 | {$R *.fmx} 35 | 36 | procedure TForm1.Button1Click(Sender: TObject); 37 | var 38 | n: TTen; 39 | s: TSuit; 40 | ss: TSuits; 41 | begin 42 | n := 5; 43 | // n := 12; 44 | s := Club; 45 | // s := 2; 46 | ss := [Diamond, Spade]; 47 | Include (ss, s); 48 | end; 49 | 50 | procedure TForm1.Show(const msg: string); 51 | begin 52 | Memo1.Lines.Add(msg); 53 | end; 54 | 55 | end. 56 | -------------------------------------------------------------------------------- /01_Basics/06_IfTest/IfTest.dpr: -------------------------------------------------------------------------------- 1 | program IfTest; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | IfTestForm in 'IfTestForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /01_Basics/06_IfTest/IfTest.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/06_IfTest/IfTest.res -------------------------------------------------------------------------------- /01_Basics/06_IfTest/IfTestForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Align = Client 15 | Size.Width = 384.000000000000000000 16 | Size.Height = 380.000000000000000000 17 | Size.PlatformDefault = False 18 | TabOrder = 0 19 | Viewport.Width = 376.000000000000000000 20 | Viewport.Height = 372.000000000000000000 21 | end 22 | object Button1: TButton 23 | Align = Top 24 | Size.Width = 384.000000000000000000 25 | Size.Height = 44.000000000000000000 26 | Size.PlatformDefault = False 27 | TabOrder = 1 28 | Text = 'if-then' 29 | OnClick = Button1Click 30 | end 31 | object CheckBox1: TCheckBox 32 | Align = Top 33 | Position.Y = 44.000000000000000000 34 | Size.Width = 384.000000000000000000 35 | Size.Height = 23.000000000000000000 36 | Size.PlatformDefault = False 37 | TabOrder = 2 38 | Text = 'CheckBox1' 39 | end 40 | object Button2: TButton 41 | Align = Top 42 | Position.Y = 67.000000000000000000 43 | Size.Width = 384.000000000000000000 44 | Size.Height = 44.000000000000000000 45 | Size.PlatformDefault = False 46 | TabOrder = 3 47 | Text = 'if-then-else' 48 | OnClick = Button2Click 49 | end 50 | object Edit1: TEdit 51 | Touch.InteractiveGestures = [LongTap, DoubleTap] 52 | Align = Top 53 | TabOrder = 4 54 | Text = 'hello' 55 | Position.Y = 111.000000000000000000 56 | Size.Width = 384.000000000000000000 57 | Size.Height = 32.000000000000000000 58 | Size.PlatformDefault = False 59 | end 60 | object Button3: TButton 61 | Align = Top 62 | Position.Y = 143.000000000000000000 63 | Size.Width = 384.000000000000000000 64 | Size.Height = 44.000000000000000000 65 | Size.PlatformDefault = False 66 | TabOrder = 5 67 | Text = 'nested if' 68 | OnClick = Button3Click 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /01_Basics/06_IfTest/IfTestForm.pas: -------------------------------------------------------------------------------- 1 | unit IfTestForm; 2 | 3 | interface 4 | 5 | // running this program raises an exception by design 6 | 7 | uses 8 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 9 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 10 | FMX.Layouts, FMX.Memo, FMX.Edit, FMX.Controls.Presentation, FMX.ScrollBox; 11 | 12 | type 13 | TForm1 = class(TForm) 14 | Memo1: TMemo; 15 | Button1: TButton; 16 | CheckBox1: TCheckBox; 17 | Button2: TButton; 18 | Edit1: TEdit; 19 | Button3: TButton; 20 | procedure Button1Click(Sender: TObject); 21 | procedure Button2Click(Sender: TObject); 22 | procedure Button3Click(Sender: TObject); 23 | private 24 | { Private declarations } 25 | public 26 | procedure Show (const msg: string); 27 | end; 28 | 29 | var 30 | Form1: TForm1; 31 | 32 | implementation 33 | 34 | {$R *.fmx} 35 | 36 | uses 37 | Character; 38 | 39 | procedure TForm1.Button1Click(Sender: TObject); 40 | var 41 | isChecked: Boolean; 42 | begin 43 | isChecked := CheckBox1.IsChecked; 44 | if isChecked then 45 | Show ('Checkbox is checked'); 46 | end; 47 | 48 | procedure TForm1.Button2Click(Sender: TObject); 49 | begin 50 | // if-then-else statement 51 | if CheckBox1.IsChecked then 52 | Show ('Checkbox is checked') 53 | else 54 | Show ('Checkbox is not checked'); 55 | end; 56 | 57 | procedure TForm1.Button3Click(Sender: TObject); 58 | var 59 | aChar: Char; 60 | begin 61 | /// multiple nested if statements 62 | if Edit1.Text.Length > 0 then 63 | begin 64 | aChar := Edit1.Text.Chars[0]; 65 | 66 | // checks for a lowercase char (two conditions) 67 | if (aChar >= 'a') and (aChar <= 'z') then 68 | Show ('char is lowercase'); 69 | 70 | // follow up conditions 71 | if aChar <= Char(47) then 72 | Show ('char is lower symbol') 73 | else if (aChar >= '0') and (aChar <= '9') then 74 | Show ('char is a number') 75 | else 76 | Show ('char is not a number or lower symbol'); 77 | end; 78 | end; 79 | 80 | procedure TForm1.Show(const msg: string); 81 | begin 82 | Memo1.Lines.Add(msg); 83 | end; 84 | 85 | end. 86 | -------------------------------------------------------------------------------- /01_Basics/07_ForTest/ForTest.dpr: -------------------------------------------------------------------------------- 1 | program ForTest; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | ForTestForm in 'ForTestForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /01_Basics/07_ForTest/ForTest.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/07_ForTest/ForTest.res -------------------------------------------------------------------------------- /01_Basics/07_ForTest/ForTestForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Align = Client 15 | Size.Width = 384.000000000000000000 16 | Size.Height = 391.000000000000000000 17 | Size.PlatformDefault = False 18 | TabOrder = 0 19 | Viewport.Width = 376.000000000000000000 20 | Viewport.Height = 383.000000000000000000 21 | end 22 | object Button1: TButton 23 | Align = Top 24 | Size.Width = 384.000000000000000000 25 | Size.Height = 44.000000000000000000 26 | Size.PlatformDefault = False 27 | TabOrder = 1 28 | Text = 'for' 29 | OnClick = Button1Click 30 | end 31 | object Button2: TButton 32 | Align = Top 33 | Position.Y = 44.000000000000000000 34 | Size.Width = 384.000000000000000000 35 | Size.Height = 44.000000000000000000 36 | Size.PlatformDefault = False 37 | TabOrder = 2 38 | Text = 'letters' 39 | OnClick = Button2Click 40 | end 41 | object Button3: TButton 42 | Align = Top 43 | Position.Y = 88.000000000000000000 44 | Size.Width = 384.000000000000000000 45 | Size.Height = 44.000000000000000000 46 | Size.PlatformDefault = False 47 | TabOrder = 3 48 | Text = 'for string' 49 | OnClick = Button3Click 50 | end 51 | object Button4: TButton 52 | Align = Top 53 | Position.Y = 132.000000000000000000 54 | Size.Width = 384.000000000000000000 55 | Size.Height = 44.000000000000000000 56 | Size.PlatformDefault = False 57 | TabOrder = 4 58 | Text = 'for-in' 59 | OnClick = Button4Click 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /01_Basics/07_ForTest/ForTestForm.pas: -------------------------------------------------------------------------------- 1 | unit ForTestForm; 2 | 3 | interface 4 | 5 | // running this program raises an exception by design 6 | 7 | uses 8 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 9 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 10 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 11 | 12 | type 13 | TForm1 = class(TForm) 14 | Memo1: TMemo; 15 | Button1: TButton; 16 | Button2: TButton; 17 | Button3: TButton; 18 | Button4: TButton; 19 | procedure Button1Click(Sender: TObject); 20 | procedure Button2Click(Sender: TObject); 21 | procedure Button3Click(Sender: TObject); 22 | procedure Button4Click(Sender: TObject); 23 | private 24 | { Private declarations } 25 | public 26 | procedure Show (const msg: string); 27 | end; 28 | 29 | var 30 | Form1: TForm1; 31 | 32 | implementation 33 | 34 | {$R *.fmx} 35 | 36 | procedure TForm1.Button1Click(Sender: TObject); 37 | var 38 | Total, I: Integer; 39 | begin 40 | Total := 0; 41 | for I := 1 to 10 do 42 | Total := Total + I; 43 | Show(Total.ToString); 44 | end; 45 | 46 | procedure TForm1.Button2Click(Sender: TObject); 47 | var 48 | aChar: Char; 49 | begin 50 | for aChar := 'a' to 'z' do 51 | Show (aChar); 52 | end; 53 | 54 | {works also with $ZEROBASEDSTRINGS ON} 55 | 56 | procedure TForm1.Button3Click(Sender: TObject); 57 | var 58 | S: string; 59 | I: Integer; 60 | begin 61 | S := 'Hello world'; 62 | for I := Low (S) to High (S) do 63 | Show(S[I]); 64 | end; 65 | 66 | procedure TForm1.Button4Click(Sender: TObject); 67 | var 68 | S: string; 69 | Ch: Char; 70 | begin 71 | S := 'Hello world'; 72 | for Ch in S do 73 | Show(Ch); 74 | end; 75 | 76 | procedure TForm1.Show(const msg: string); 77 | begin 78 | Memo1.Lines.Add(msg); 79 | end; 80 | 81 | end. 82 | -------------------------------------------------------------------------------- /01_Basics/08_OverloadTest/OverloadTest.dpr: -------------------------------------------------------------------------------- 1 | program OverloadTest; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | OverloadTestForm in 'OverloadTestForm.pas' {Form1}; 7 | 8 | {$R *.res} 9 | 10 | begin 11 | Application.Initialize; 12 | Application.CreateForm(TForm1, Form1); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /01_Basics/08_OverloadTest/OverloadTest.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/08_OverloadTest/OverloadTest.res -------------------------------------------------------------------------------- /01_Basics/08_OverloadTest/OverloadTestForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Align = Client 15 | Size.Width = 384.000000000000000000 16 | Size.Height = 435.000000000000000000 17 | Size.PlatformDefault = False 18 | TabOrder = 0 19 | Viewport.Width = 376.000000000000000000 20 | Viewport.Height = 427.000000000000000000 21 | end 22 | object Button1: TButton 23 | Align = Top 24 | Size.Width = 384.000000000000000000 25 | Size.Height = 44.000000000000000000 26 | Size.PlatformDefault = False 27 | TabOrder = 1 28 | Text = 'Overloaded ShowMsg' 29 | OnClick = Button1Click 30 | end 31 | object Button2: TButton 32 | Align = Top 33 | Position.Y = 44.000000000000000000 34 | Size.Width = 384.000000000000000000 35 | Size.Height = 44.000000000000000000 36 | Size.PlatformDefault = False 37 | TabOrder = 2 38 | Text = 'Ambiguous Call' 39 | OnClick = Button2Click 40 | end 41 | object Button3: TButton 42 | Align = Top 43 | Position.Y = 88.000000000000000000 44 | Size.Width = 384.000000000000000000 45 | Size.Height = 44.000000000000000000 46 | Size.PlatformDefault = False 47 | TabOrder = 3 48 | Text = 'Default Params' 49 | OnClick = Button3Click 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /01_Basics/08_OverloadTest/OverloadTestForm.pas: -------------------------------------------------------------------------------- 1 | unit OverloadTestForm; 2 | 3 | interface 4 | 5 | // running this program raises an exception by design 6 | 7 | uses 8 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 9 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 10 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 11 | 12 | type 13 | TForm1 = class(TForm) 14 | Memo1: TMemo; 15 | Button1: TButton; 16 | Button2: TButton; 17 | Button3: TButton; 18 | procedure Button1Click(Sender: TObject); 19 | procedure Button2Click(Sender: TObject); 20 | procedure Button3Click(Sender: TObject); 21 | private 22 | { Private declarations } 23 | public 24 | procedure Show (const msg: string); 25 | end; 26 | 27 | var 28 | Form1: TForm1; 29 | 30 | implementation 31 | 32 | {$R *.fmx} 33 | 34 | uses 35 | System.Math; 36 | 37 | procedure Show (const msg: string); 38 | begin 39 | Form1.Show(msg) 40 | end; 41 | 42 | procedure ShowMsg (str: string); overload; 43 | begin 44 | Show ('Message: ' + str); 45 | end; 46 | 47 | procedure ShowMsg (FormatStr: string; 48 | Params: array of const); overload; 49 | begin 50 | Show ('Message: ' + Format (FormatStr, Params)); 51 | end; 52 | 53 | procedure ShowMsg (I: Integer; Str: string); overload; 54 | begin 55 | ShowMsg (I.ToString + ' ' + Str); 56 | end; 57 | 58 | function Add (N: Integer; S: Single): Single; overload; 59 | begin 60 | Result := N + S; 61 | end; 62 | 63 | function Add (S: Single; N: Integer): Single; overload; 64 | begin 65 | Result := N + S; 66 | end; 67 | 68 | procedure NewMessage (Msg: string; 69 | Caption: string = 'Message'; 70 | Separator: string = ': '); overload; 71 | begin 72 | Show (Caption + Separator + Msg); 73 | end; 74 | 75 | // uncommenting this overloaded procedure will cause an ambiguous call 76 | //procedure NewMessage (Str: string; I: Integer = 0); overload; 77 | //begin 78 | // writeln (Str + ': ' + IntToStr (I)) 79 | //end; 80 | 81 | procedure TForm1.Button1Click(Sender: TObject); 82 | begin 83 | ShowMsg ('Hello'); 84 | ShowMsg ('Total = %d.', [100]); 85 | ShowMsg (10, 'MBytes'); 86 | // ShowMsg (10.0, 'Hello'); 87 | end; 88 | 89 | procedure TForm1.Button2Click(Sender: TObject); 90 | begin 91 | Show (Add (10, 10.0).ToString); 92 | Show (Add (10.0, 10).ToString); 93 | // Show (Add (10, 10).ToString); // ambiguous call 94 | Show (Add (10, 10.ToSingle).ToString); 95 | end; 96 | 97 | procedure TForm1.Button3Click(Sender: TObject); 98 | begin 99 | NewMessage ('Something wrong here!'); 100 | NewMessage ('Something wrong here!', 'Attention'); 101 | NewMessage ('Hello', 'Message', '--'); 102 | end; 103 | 104 | procedure TForm1.Show(const msg: string); 105 | begin 106 | Memo1.Lines.Add(msg); 107 | end; 108 | 109 | end. 110 | -------------------------------------------------------------------------------- /01_Basics/09_RecordMethods/RecordMethods.dpr: -------------------------------------------------------------------------------- 1 | program RecordMethods; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | RecordMethodsForm in 'RecordMethodsForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /01_Basics/09_RecordMethods/RecordMethods.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/09_RecordMethods/RecordMethods.res -------------------------------------------------------------------------------- /01_Basics/09_RecordMethods/RecordMethodsForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Align = Client 15 | Size.Width = 384.000000000000000000 16 | Size.Height = 435.000000000000000000 17 | Size.PlatformDefault = False 18 | TabOrder = 0 19 | Viewport.Width = 376.000000000000000000 20 | Viewport.Height = 427.000000000000000000 21 | end 22 | object Button1: TButton 23 | Align = Top 24 | Position.Y = 44.000000000000000000 25 | Size.Width = 384.000000000000000000 26 | Size.Height = 44.000000000000000000 27 | Size.PlatformDefault = False 28 | TabOrder = 1 29 | Text = 'Record Methods' 30 | OnClick = Button1Click 31 | end 32 | object Button2: TButton 33 | Align = Top 34 | Position.Y = 88.000000000000000000 35 | Size.Width = 384.000000000000000000 36 | Size.Height = 44.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 2 39 | Text = 'Uninitialized Data' 40 | OnClick = Button2Click 41 | end 42 | object Button3: TButton 43 | Align = Top 44 | Size.Width = 384.000000000000000000 45 | Size.Height = 44.000000000000000000 46 | Size.PlatformDefault = False 47 | TabOrder = 3 48 | Text = 'Plain Record' 49 | OnClick = Button3Click 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /01_Basics/09_RecordMethods/RecordMethodsForm.pas: -------------------------------------------------------------------------------- 1 | unit RecordMethodsForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 9 | 10 | type 11 | TForm1 = class(TForm) 12 | Memo1: TMemo; 13 | Button1: TButton; 14 | Button2: TButton; 15 | Button3: TButton; 16 | procedure Button1Click(Sender: TObject); 17 | procedure Button2Click(Sender: TObject); 18 | procedure Button3Click(Sender: TObject); 19 | private 20 | { Private declarations } 21 | public 22 | procedure Show (const msg: string); 23 | end; 24 | 25 | var 26 | Form1: TForm1; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | type 33 | TMyRecord = record 34 | private 35 | Name: string; 36 | Value: Integer; 37 | SomeChar: Char; 38 | public 39 | function ToString: string; 40 | procedure SetValue (NewString: string); 41 | procedure Init (NewValue: Integer); 42 | end; 43 | 44 | procedure TForm1.Button1Click(Sender: TObject); 45 | var 46 | MyRec: TMyRecord; 47 | begin 48 | MyRec.Init(10); 49 | MyRec.SetValue ('hello'); 50 | Show (MyRec.ToString); 51 | MyRec.Value := 20; // actually works! 52 | end; 53 | 54 | procedure TForm1.Button2Click(Sender: TObject); 55 | var 56 | MyRec: TMyRecord; 57 | begin 58 | Show (MyRec.ToString); 59 | end; 60 | 61 | function DoubleTheRecord (ARec: TMyRecord): TMyRecord; 62 | begin 63 | Result.Name := ARec.Name + ' ' + ARec.Name; 64 | Result.Value := ARec.Value * 2; 65 | end; 66 | 67 | procedure TForm1.Button3Click(Sender: TObject); 68 | var 69 | MyRec: TMyRecord; 70 | begin 71 | MyRec.Name := 'Joe'; 72 | MyRec.Value := 21; 73 | 74 | MyRec := DoubleTheRecord (MyRec); 75 | 76 | Show (MyRec.Name + ': ' + MyRec.Value.ToString); 77 | end; 78 | 79 | procedure TForm1.Show(const msg: string); 80 | begin 81 | Memo1.Lines.Add(msg); 82 | end; 83 | 84 | { TMyRecord } 85 | 86 | procedure TMyRecord.Init(NewValue: Integer); 87 | begin 88 | Value := NewValue; 89 | SomeChar := 'A'; 90 | end; 91 | 92 | function TMyRecord.ToString: string; 93 | begin 94 | Result := Name + ' [' + SomeChar + ']: ' + Value.ToString; 95 | end; 96 | 97 | procedure TMyRecord.SetValue(NewString: string); 98 | begin 99 | Name := NewString; 100 | end; 101 | 102 | end. 103 | -------------------------------------------------------------------------------- /01_Basics/10_OperatorsOver/OperatorsOver.dpr: -------------------------------------------------------------------------------- 1 | program OperatorsOver; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | OperatorsOverForm in 'OperatorsOverForm.pas' {Form1}, 8 | OperatorsTypes in 'OperatorsTypes.pas'; 9 | 10 | {$R *.res} 11 | 12 | begin 13 | Application.Initialize; 14 | Application.CreateForm(TForm1, Form1); 15 | Application.Run; 16 | end. 17 | -------------------------------------------------------------------------------- /01_Basics/10_OperatorsOver/OperatorsOver.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/10_OperatorsOver/OperatorsOver.res -------------------------------------------------------------------------------- /01_Basics/10_OperatorsOver/OperatorsOverForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Align = Client 15 | Size.Width = 384.000000000000000000 16 | Size.Height = 435.000000000000000000 17 | Size.PlatformDefault = False 18 | TabOrder = 0 19 | Viewport.Width = 376.000000000000000000 20 | Viewport.Height = 427.000000000000000000 21 | end 22 | object Button1: TButton 23 | Align = Top 24 | Size.Width = 384.000000000000000000 25 | Size.Height = 44.000000000000000000 26 | Size.PlatformDefault = False 27 | TabOrder = 1 28 | Text = 'Add Records' 29 | OnClick = Button1Click 30 | end 31 | object Button2: TButton 32 | Align = Top 33 | Position.Y = 44.000000000000000000 34 | Size.Width = 384.000000000000000000 35 | Size.Height = 44.000000000000000000 36 | Size.PlatformDefault = False 37 | TabOrder = 2 38 | Text = 'Commutativity' 39 | OnClick = Button2Click 40 | end 41 | object Button3: TButton 42 | Align = Top 43 | Position.Y = 88.000000000000000000 44 | Size.Width = 384.000000000000000000 45 | Size.Height = 44.000000000000000000 46 | Size.PlatformDefault = False 47 | TabOrder = 3 48 | Text = 'Conversions and Promotions' 49 | OnClick = Button3Click 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /01_Basics/10_OperatorsOver/OperatorsOverForm.pas: -------------------------------------------------------------------------------- 1 | unit OperatorsOverForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 9 | 10 | type 11 | TForm1 = class(TForm) 12 | Memo1: TMemo; 13 | Button1: TButton; 14 | Button2: TButton; 15 | Button3: TButton; 16 | procedure Button1Click(Sender: TObject); 17 | procedure Button2Click(Sender: TObject); 18 | procedure Button3Click(Sender: TObject); 19 | private 20 | { Private declarations } 21 | public 22 | procedure Show (const msg: string); 23 | end; 24 | 25 | var 26 | Form1: TForm1; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | uses 33 | OperatorsTypes; 34 | 35 | procedure TForm1.Button1Click(Sender: TObject); 36 | var 37 | a, b, c: TPointRecord; 38 | begin 39 | a.SetValue(10, 10); 40 | b := 30; 41 | c := a + b; 42 | Show (string(c)); 43 | end; 44 | 45 | procedure TForm1.Button2Click(Sender: TObject); 46 | var 47 | a: TPointRecord2; 48 | begin 49 | a.SetValue(10, 20); 50 | a := a + 10; 51 | a := 30 + a; 52 | Show (string(a)); 53 | end; 54 | 55 | procedure TForm1.Button3Click(Sender: TObject); 56 | var 57 | a, c: TPointRecord; 58 | begin 59 | a := 50; 60 | 61 | c := a + 30; 62 | Show (string(c)); 63 | 64 | c := 50 + 30; 65 | Show (string(c)); 66 | 67 | c := 50 + TPointRecord(30); 68 | Show (string(c)); 69 | 70 | end; 71 | 72 | procedure TForm1.Show(const msg: string); 73 | begin 74 | Memo1.Lines.Add(msg); 75 | end; 76 | 77 | end. 78 | -------------------------------------------------------------------------------- /01_Basics/10_OperatorsOver/OperatorsTypes.pas: -------------------------------------------------------------------------------- 1 | unit OperatorsTypes; 2 | 3 | interface 4 | 5 | uses 6 | SysUtils; 7 | 8 | type 9 | TPointRecord = record 10 | private 11 | x, y: Integer; 12 | public 13 | procedure SetValue (x1, y1: Integer); 14 | class operator Add (a, b: TPointRecord): TPointRecord; 15 | class operator Explicit (a: TPointRecord) : string; 16 | class operator Implicit (x1: Integer): TPointRecord; 17 | end; 18 | 19 | type 20 | TPointRecord2 = record 21 | private 22 | x, y: Integer; 23 | public 24 | class operator Explicit (a: TPointRecord2) : string; 25 | procedure SetValue (x1, y1: Integer); 26 | // commutativity 27 | class operator Add (a: TPointRecord2; b: Integer): TPointRecord2; 28 | class operator Add (b: Integer; a: TPointRecord2): TPointRecord2; 29 | end; 30 | 31 | 32 | implementation 33 | 34 | { TPointRecord } 35 | 36 | class operator TPointRecord.Add(a, b: TPointRecord): TPointRecord; 37 | begin 38 | Result.x := a.x + b.x; 39 | Result.y := a.y + b.y; 40 | end; 41 | 42 | class operator TPointRecord.Explicit(a: TPointRecord): string; 43 | begin 44 | Result := Format('(%d:%d)', [a.x, a.y]); 45 | end; 46 | 47 | class operator TPointRecord.Implicit(x1: Integer): TPointRecord; 48 | begin 49 | Result.x := x1; 50 | Result.y := 10; 51 | end; 52 | 53 | procedure TPointRecord.SetValue(x1, y1: Integer); 54 | begin 55 | x := x1; 56 | y := y1; 57 | end; 58 | 59 | { TPointRecord2 } 60 | 61 | procedure TPointRecord2.SetValue(x1, y1: Integer); 62 | begin 63 | x := x1; 64 | y := y1; 65 | end; 66 | 67 | class operator TPointRecord2.Add(a: TPointRecord2; b: Integer): TPointRecord2; 68 | begin 69 | Result.x := a.x + b; 70 | Result.y := a.y + b; 71 | end; 72 | 73 | class operator TPointRecord2.Add(b: Integer; a: TPointRecord2): TPointRecord2; 74 | begin 75 | Result := a + b; // implement commutativity 76 | end; 77 | 78 | class operator TPointRecord2.Explicit(a: TPointRecord2): string; 79 | begin 80 | Result := Format('(%d:%d)', [a.x, a.y]); 81 | end; 82 | 83 | end. 84 | -------------------------------------------------------------------------------- /01_Basics/11_StringHelperTest/StringHelperForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Align = Client 15 | Size.Width = 384.000000000000000000 16 | Size.Height = 479.000000000000000000 17 | Size.PlatformDefault = False 18 | TabOrder = 0 19 | Viewport.Width = 376.000000000000000000 20 | Viewport.Height = 471.000000000000000000 21 | end 22 | object Button1: TButton 23 | Align = Top 24 | Size.Width = 384.000000000000000000 25 | Size.Height = 44.000000000000000000 26 | Size.PlatformDefault = False 27 | TabOrder = 1 28 | Text = 'Find' 29 | OnClick = Button1Click 30 | end 31 | object Button2: TButton 32 | Align = Top 33 | Position.Y = 44.000000000000000000 34 | Size.Width = 384.000000000000000000 35 | Size.Height = 44.000000000000000000 36 | Size.PlatformDefault = False 37 | TabOrder = 2 38 | Text = 'Replace' 39 | OnClick = Button2Click 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /01_Basics/11_StringHelperTest/StringHelperForm.pas: -------------------------------------------------------------------------------- 1 | unit StringHelperForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 9 | 10 | type 11 | TForm1 = class(TForm) 12 | Memo1: TMemo; 13 | Button1: TButton; 14 | Button2: TButton; 15 | procedure Button1Click(Sender: TObject); 16 | procedure Button2Click(Sender: TObject); 17 | private 18 | { Private declarations } 19 | public 20 | procedure Show (const msg: string); 21 | end; 22 | 23 | var 24 | Form1: TForm1; 25 | 26 | implementation 27 | 28 | {$R *.fmx} 29 | 30 | procedure TForm1.Button1Click(Sender: TObject); 31 | var 32 | str1, str2: string; 33 | I, nCount: Integer; 34 | begin 35 | str1 := ''; 36 | 37 | // create string 38 | for I := 1 to 10 do 39 | str1 := str1 + 'Object '; 40 | 41 | str2:= string.Copy (str1); 42 | str1 := str2 + 'Pascal ' + str2.Substring (10, 30); 43 | Show(str1); 44 | 45 | // find substring 46 | Show('Pascal at: ' + 47 | str1.IndexOf ('Pascal').ToString); 48 | 49 | // count occurrences 50 | I := -1; 51 | nCount := 0; 52 | repeat 53 | I := str1.IndexOf('O', I + 1); // search from next element 54 | if I >= 0 then 55 | Inc (nCount); // found one 56 | until I < 0; 57 | 58 | Show('O found: ' + 59 | nCount.ToString + ' times'); 60 | end; 61 | 62 | procedure TForm1.Button2Click(Sender: TObject); 63 | var 64 | str1, str2: string; 65 | I, nIndex: Integer; 66 | begin 67 | str1 := ''; 68 | 69 | // create string 70 | for I := 1 to 10 do 71 | str1 := str1 + 'Object '; 72 | 73 | str2:= string.Copy (str1); 74 | str1 := str2 + 'Pascal ' + str2.Substring (10, 30); 75 | Show(str1); 76 | 77 | // single replace 78 | nIndex := str1.IndexOf ('Pascal'); 79 | str1 := str1.Substring(0, nIndex) + 'Object' + 80 | str1.Substring(nIndex + ('Pascal').Length); 81 | Show (str1); 82 | 83 | // multi-replace 84 | str1 := str1.Replace('O', 'o', [rfReplaceAll]); 85 | Show (str1); 86 | end; 87 | 88 | procedure TForm1.Show(const Msg: string); 89 | begin 90 | Memo1.Lines.Add(Msg); 91 | end; 92 | 93 | end. 94 | -------------------------------------------------------------------------------- /01_Basics/11_StringHelperTest/StringHelperTest.dpr: -------------------------------------------------------------------------------- 1 | program StringHelperTest; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | StringHelperForm in 'StringHelperForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /01_Basics/11_StringHelperTest/StringHelperTest.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/11_StringHelperTest/StringHelperTest.res -------------------------------------------------------------------------------- /01_Basics/12_StringMetaTest/StringMetaTest.dpr: -------------------------------------------------------------------------------- 1 | program StringMetaTest; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | StringMetaTestForm in 'StringMetaTestForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /01_Basics/12_StringMetaTest/StringMetaTest.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/12_StringMetaTest/StringMetaTest.res -------------------------------------------------------------------------------- /01_Basics/12_StringMetaTest/StringMetaTestForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | OnCreate = FormCreate 11 | DesignerMasterStyle = 3 12 | object Memo1: TMemo 13 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 14 | DataDetectorTypes = [] 15 | Align = Client 16 | Size.Width = 384.000000000000000000 17 | Size.Height = 479.000000000000000000 18 | Size.PlatformDefault = False 19 | TabOrder = 0 20 | Viewport.Width = 376.000000000000000000 21 | Viewport.Height = 471.000000000000000000 22 | end 23 | object Button1: TButton 24 | Align = Top 25 | Size.Width = 384.000000000000000000 26 | Size.Height = 44.000000000000000000 27 | Size.PlatformDefault = False 28 | TabOrder = 1 29 | Text = 'Get String Metadata' 30 | OnClick = Button1Click 31 | end 32 | object Button2: TButton 33 | Align = Top 34 | Position.Y = 44.000000000000000000 35 | Size.Width = 384.000000000000000000 36 | Size.Height = 44.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 2 39 | Text = 'String References' 40 | OnClick = Button2Click 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /01_Basics/12_StringMetaTest/StringMetaTestForm.pas: -------------------------------------------------------------------------------- 1 | unit StringMetaTestForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.Edit, FMX.Controls.Presentation, FMX.ScrollBox; 9 | 10 | type 11 | TForm1 = class(TForm) 12 | Memo1: TMemo; 13 | Button1: TButton; 14 | Button2: TButton; 15 | procedure Button1Click(Sender: TObject); 16 | procedure FormCreate(Sender: TObject); 17 | procedure Button2Click(Sender: TObject); 18 | private 19 | { Private declarations } 20 | public 21 | procedure Show (const msg: string); 22 | end; 23 | 24 | var 25 | Form1: TForm1; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | {$ZEROBASEDSTRINGS ON} 32 | 33 | var 34 | MyStr1, MyStr2: string; 35 | 36 | procedure TForm1.Button1Click(Sender: TObject); 37 | var 38 | str1: string; 39 | begin 40 | str1 := 'F' + string.Create ('o', 2); 41 | 42 | Show ('SizeOf: ' + SizeOf (str1).ToString); 43 | Show ('Length: ' + str1.Length.ToString); 44 | Show ('StringElementSize: ' + 45 | StringElementSize (str1).ToString); 46 | Show ('StringRefCount: ' + 47 | StringRefCount (str1).ToString); 48 | Show ('StringCodePage: ' + 49 | StringCodePage (str1).ToString); 50 | if StringCodePage (str1) = DefaultUnicodeCodePage then 51 | Show ('Is Unicode'); 52 | Show ('Size in bytes: ' + 53 | (Length (str1) * StringElementSize (str1)).ToString); 54 | Show ('ByteLength: ' + 55 | ByteLength (str1).ToString); 56 | end; 57 | 58 | function StringStatus (const Str: string): string; 59 | begin 60 | Result := 'Addr: ' + 61 | IntToStr (Integer (Str)) + 62 | ', Len: ' + 63 | IntToStr (Length (Str)) + 64 | ', Ref: ' + 65 | IntToStr (PInteger (Integer (Str) - 8)^) + 66 | ', Val: ' + Str; 67 | end; 68 | 69 | procedure TForm1.Button2Click(Sender: TObject); 70 | begin 71 | Show ('MyStr1 - ' + StringStatus (MyStr1)); 72 | Show ('MyStr2 - ' + StringStatus (MyStr2)); 73 | MyStr1 [1] := 'a'; 74 | Show ('Change 2nd char'); 75 | Show ('MyStr1 - ' + StringStatus (MyStr1)); 76 | Show ('MyStr2 - ' + StringStatus (MyStr2)); 77 | end; 78 | 79 | procedure TForm1.FormCreate(Sender: TObject); 80 | begin 81 | MyStr1 := string.Create(['H', 'e', 'l', 'l', 'o']); 82 | MyStr2 := MyStr1; 83 | end; 84 | 85 | procedure TForm1.Show(const Msg: string); 86 | begin 87 | Memo1.Lines.Add(Msg); 88 | end; 89 | 90 | end. 91 | -------------------------------------------------------------------------------- /01_Basics/13_PointersTest/PointersTest.dpr: -------------------------------------------------------------------------------- 1 | program PointersTest; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | PointersTestForm in 'PointersTestForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /01_Basics/13_PointersTest/PointersTest.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/01_Basics/13_PointersTest/PointersTest.res -------------------------------------------------------------------------------- /01_Basics/13_PointersTest/PointersTestForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Align = Client 15 | Size.Width = 384.000000000000000000 16 | Size.Height = 435.000000000000000000 17 | Size.PlatformDefault = False 18 | TabOrder = 0 19 | Viewport.Width = 376.000000000000000000 20 | Viewport.Height = 427.000000000000000000 21 | end 22 | object Button1: TButton 23 | Align = Top 24 | Size.Width = 384.000000000000000000 25 | Size.Height = 44.000000000000000000 26 | Size.PlatformDefault = False 27 | TabOrder = 1 28 | Text = 'Pointers 101' 29 | OnClick = Button1Click 30 | end 31 | object Button2: TButton 32 | Align = Top 33 | Position.Y = 44.000000000000000000 34 | Size.Width = 384.000000000000000000 35 | Size.Height = 44.000000000000000000 36 | Size.PlatformDefault = False 37 | TabOrder = 2 38 | Text = 'Dynamic Allocation' 39 | OnClick = Button2Click 40 | end 41 | object Button3: TButton 42 | Align = Top 43 | Position.Y = 88.000000000000000000 44 | Size.Width = 384.000000000000000000 45 | Size.Height = 44.000000000000000000 46 | Size.PlatformDefault = False 47 | TabOrder = 3 48 | Text = 'Access Violation' 49 | OnClick = Button3Click 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /01_Basics/13_PointersTest/PointersTestForm.pas: -------------------------------------------------------------------------------- 1 | unit PointersTestForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 9 | 10 | type 11 | TForm1 = class(TForm) 12 | Memo1: TMemo; 13 | Button1: TButton; 14 | Button2: TButton; 15 | Button3: TButton; 16 | procedure Button1Click(Sender: TObject); 17 | procedure Button2Click(Sender: TObject); 18 | procedure Button3Click(Sender: TObject); 19 | private 20 | { Private declarations } 21 | public 22 | procedure Show (const msg: string); 23 | end; 24 | 25 | var 26 | Form1: TForm1; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | type 33 | TPointerToInt = ^Integer; 34 | 35 | procedure TForm1.Button1Click(Sender: TObject); 36 | var 37 | P: ^Integer; 38 | X: Integer; 39 | begin 40 | X := 10; 41 | P := @X; 42 | // change the value of X using the pointer 43 | P^ := 20; 44 | Show ('X: ' + X.ToString); 45 | Show ('P^: ' + P^.ToString); 46 | Show ('P: ' + Integer(P).ToHexString (8)); 47 | end; 48 | 49 | procedure TForm1.Button2Click(Sender: TObject); 50 | var 51 | P: ^Integer; 52 | begin 53 | // initialization 54 | New (P); 55 | // operations 56 | P^ := 20; 57 | Show (P^.ToString); 58 | // termination 59 | Dispose (P); 60 | end; 61 | 62 | procedure TForm1.Button3Click(Sender: TObject); 63 | var 64 | P: ^Integer; 65 | begin 66 | P := nil; 67 | // if Assigned (P) then 68 | Show (P^.ToString); 69 | end; 70 | 71 | procedure TForm1.Show(const msg: string); 72 | begin 73 | Memo1.Lines.Add(msg); 74 | end; 75 | 76 | end. 77 | -------------------------------------------------------------------------------- /02_OOP/01_Dates4/Dates4.dpr: -------------------------------------------------------------------------------- 1 | program Dates4; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | FMX.MobilePreview, 7 | DatesForm in 'DatesForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /02_OOP/01_Dates4/Dates4.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/02_OOP/01_Dates4/Dates4.res -------------------------------------------------------------------------------- /02_OOP/01_Dates4/DatesForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Align = Client 15 | Size.Width = 384.000000000000000000 16 | Size.Height = 435.000000000000000000 17 | Size.PlatformDefault = False 18 | TabOrder = 0 19 | Viewport.Width = 376.000000000000000000 20 | Viewport.Height = 427.000000000000000000 21 | end 22 | object Button1: TButton 23 | Align = Top 24 | Size.Width = 384.000000000000000000 25 | Size.Height = 44.000000000000000000 26 | Size.PlatformDefault = False 27 | TabOrder = 1 28 | Text = 'Today' 29 | OnClick = Button1Click 30 | end 31 | object Button2: TButton 32 | Align = Top 33 | Position.Y = 44.000000000000000000 34 | Size.Width = 384.000000000000000000 35 | Size.Height = 44.000000000000000000 36 | Size.PlatformDefault = False 37 | TabOrder = 2 38 | Text = 'Set Date' 39 | OnClick = Button2Click 40 | end 41 | object Button3: TButton 42 | Align = Top 43 | Position.Y = 88.000000000000000000 44 | Size.Width = 384.000000000000000000 45 | Size.Height = 44.000000000000000000 46 | Size.PlatformDefault = False 47 | TabOrder = 3 48 | Text = 'Use Person' 49 | OnClick = Button3Click 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /02_OOP/01_Dates4/DatesForm.pas: -------------------------------------------------------------------------------- 1 | unit DatesForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 9 | 10 | type 11 | TForm1 = class(TForm) 12 | Memo1: TMemo; 13 | Button1: TButton; 14 | Button2: TButton; 15 | Button3: TButton; 16 | procedure Button1Click(Sender: TObject); 17 | procedure Button2Click(Sender: TObject); 18 | procedure Button3Click(Sender: TObject); 19 | private 20 | { Private declarations } 21 | public 22 | procedure Show (const msg: string); 23 | end; 24 | 25 | var 26 | Form1: TForm1; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | uses 33 | DateUtils; 34 | 35 | type 36 | TDate = class 37 | private 38 | FDate: TDateTime; 39 | public 40 | constructor Create; overload; 41 | constructor Create (Month, Day, Year: Integer); overload; 42 | procedure SetValue (Month, Day, Year: Integer); overload; 43 | procedure SetValue (NewDate: TDateTime); overload; 44 | function LeapYear: Boolean; 45 | function GetText: string; 46 | procedure Increase; 47 | end; 48 | 49 | constructor TDate.Create; 50 | begin 51 | FDate := Today; 52 | end; 53 | 54 | constructor TDate.Create (Month, Day, Year: Integer); 55 | begin 56 | FDate := EncodeDate (Year, Month, Day); 57 | end; 58 | 59 | procedure TDate.SetValue (Month, Day, Year: Integer); 60 | begin 61 | FDate := EncodeDate (Year, Month, Day); 62 | end; 63 | 64 | function TDate.GetText: string; 65 | begin 66 | Result := DateToStr (FDate); 67 | end; 68 | 69 | procedure TDate.Increase; 70 | begin 71 | FDate := FDate + 1; 72 | end; 73 | 74 | function TDate.LeapYear: Boolean; 75 | begin 76 | // call IsLeapYear in SysUtils and YearOf in DateUtils 77 | Result := IsLeapYear (YearOf (FDate)); 78 | end; 79 | 80 | procedure TDate.SetValue(NewDate: TDateTime); 81 | begin 82 | FDate := NewDate; 83 | end; 84 | 85 | // class demostrating destructors and resource management 86 | 87 | type 88 | TPerson = class 89 | private 90 | FName: string; 91 | FBirthDate: TDate; 92 | public 93 | constructor Create (name: string); 94 | destructor Destroy; override; 95 | // some actual methods 96 | function Info: string; 97 | end; 98 | 99 | 100 | procedure TForm1.Button1Click(Sender: TObject); 101 | var 102 | ADay: TDate; 103 | begin 104 | // create 105 | ADay := TDate.Create; // today 106 | 107 | // use 108 | ADay.Increase; 109 | 110 | if ADay.LeapYear then 111 | Show ('Leap year: ' + ADay.GetText) 112 | else 113 | Show ('Not a leap year: ' + ADay.GetText); 114 | 115 | // free the memory (for non ARC platforms) 116 | ADay.Free; 117 | end; 118 | 119 | procedure TForm1.Button2Click(Sender: TObject); 120 | var 121 | ADay: TDate; 122 | begin 123 | // create 124 | ADay := TDate.Create (1, 1, 2016); 125 | 126 | // use 127 | ADay.Increase; 128 | 129 | if ADay.LeapYear then 130 | Show ('Leap year: ' + ADay.GetText); 131 | 132 | // free the memory (for non ARC platforms) 133 | ADay.Free; 134 | end; 135 | 136 | procedure TForm1.Button3Click(Sender: TObject); 137 | var 138 | Person: TPerson; 139 | begin 140 | Person := TPerson.Create ('John'); 141 | // use the class and its internal object 142 | Show (Person.Info); 143 | Person.Free; 144 | end; 145 | 146 | procedure TForm1.Show(const Msg: string); 147 | begin 148 | Memo1.Lines.Add(Msg); 149 | end; 150 | 151 | { TPerson } 152 | 153 | constructor TPerson.Create(name: string); 154 | begin 155 | FName := Name; 156 | FBirthDate := TDate.Create; 157 | end; 158 | 159 | destructor TPerson.Destroy; 160 | begin 161 | FBirthDate.Free; 162 | inherited; 163 | end; 164 | 165 | function TPerson.Info: string; 166 | begin 167 | Result := FName + ': ' + FBirthDate.GetText; 168 | end; 169 | 170 | end. 171 | -------------------------------------------------------------------------------- /02_OOP/02_ClicksCount/ClicksCount.dpr: -------------------------------------------------------------------------------- 1 | program ClicksCount; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | ClicksCountForm in 'ClicksCountForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /02_OOP/02_ClicksCount/ClicksCount.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/02_OOP/02_ClicksCount/ClicksCount.res -------------------------------------------------------------------------------- /02_OOP/02_ClicksCount/ClicksCountForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | OnMouseDown = FormMouseDown 11 | DesignerMasterStyle = 3 12 | object Label1: TLabel 13 | Align = Top 14 | Position.Y = 44.000000000000000000 15 | Size.Width = 384.000000000000000000 16 | Size.Height = 41.000000000000000000 17 | Size.PlatformDefault = False 18 | TextSettings.HorzAlign = Center 19 | Text = '0' 20 | end 21 | object Button1: TButton 22 | Align = Top 23 | Size.Width = 384.000000000000000000 24 | Size.Height = 44.000000000000000000 25 | Size.PlatformDefault = False 26 | TabOrder = 1 27 | Text = 'New Form' 28 | OnClick = Button1Click 29 | end 30 | object Button2: TButton 31 | Align = Bottom 32 | Position.Y = 523.000000000000000000 33 | Size.Width = 384.000000000000000000 34 | Size.Height = 44.000000000000000000 35 | Size.PlatformDefault = False 36 | TabOrder = 2 37 | Text = 'Close' 38 | OnClick = Button2Click 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /02_OOP/02_ClicksCount/ClicksCountForm.pas: -------------------------------------------------------------------------------- 1 | unit ClicksCountForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Controls.Presentation; 9 | 10 | type 11 | TForm1 = class(TForm) 12 | Label1: TLabel; 13 | Button1: TButton; 14 | Button2: TButton; 15 | procedure FormMouseDown(Sender: TObject; Button: TMouseButton; 16 | Shift: TShiftState; X, Y: Single); 17 | procedure Button1Click(Sender: TObject); 18 | procedure Button2Click(Sender: TObject); 19 | public 20 | function GetClicks: Integer; 21 | private 22 | nClicks: Integer; 23 | end; 24 | 25 | var 26 | Form1: TForm1; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TForm1.Button1Click(Sender: TObject); 33 | var 34 | NewForm: TForm1; 35 | begin 36 | NewForm := TForm1.Create(Application); 37 | NewForm.Show; 38 | end; 39 | 40 | procedure TForm1.Button2Click(Sender: TObject); 41 | begin 42 | Close; 43 | end; 44 | 45 | procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; 46 | Shift: TShiftState; X, Y: Single); 47 | begin 48 | Inc (nClicks); 49 | Label1.Text := nClicks.ToString; 50 | end; 51 | 52 | function TForm1.GetClicks: Integer; 53 | begin 54 | Result := nClicks; 55 | end; 56 | 57 | end. 58 | -------------------------------------------------------------------------------- /02_OOP/03_DerivedDates/Dates.pas: -------------------------------------------------------------------------------- 1 | unit Dates; 2 | 3 | interface 4 | 5 | type 6 | TDate = class 7 | private 8 | FDate: TDateTime; 9 | public 10 | constructor Create; overload; 11 | constructor Create (Month, Day, Year: Integer); overload; 12 | procedure SetValue (Month, Day, Year: Integer); overload; 13 | procedure SetValue (NewDate: TDateTime); overload; 14 | function LeapYear: Boolean; 15 | procedure Increase (NumberOfDays: Integer = 1); 16 | procedure Decrease (NumberOfDays: Integer = 1); 17 | function GetText: string; 18 | end; 19 | 20 | TNewDate = class (TDate) 21 | public 22 | function GetText: string; 23 | end; 24 | 25 | implementation 26 | 27 | uses 28 | SysUtils, DateUtils; 29 | 30 | constructor TDate.Create; 31 | begin 32 | FDate := Today; 33 | end; 34 | 35 | constructor TDate.Create (Month, Day, Year: Integer); 36 | begin 37 | FDate := EncodeDate (Year, Month, Day); 38 | end; 39 | 40 | procedure TDate.Decrease(NumberOfDays: Integer); 41 | begin 42 | FDate := FDate - NumberOfDays; 43 | end; 44 | 45 | procedure TDate.SetValue (Month, Day, Year: Integer); 46 | begin 47 | FDate := EncodeDate (Year, Month, Day); 48 | end; 49 | 50 | function TDate.GetText: string; 51 | begin 52 | Result := DateToStr (FDate); 53 | end; 54 | 55 | procedure TDate.Increase (NumberOfDays: Integer); 56 | begin 57 | FDate := FDate + NumberOfDays; 58 | end; 59 | 60 | function TDate.LeapYear: Boolean; 61 | begin 62 | // call IsLeapYear in SysUtils and YearOf in DateUtils 63 | Result := IsLeapYear (YearOf (FDate)); 64 | end; 65 | 66 | procedure TDate.SetValue(NewDate: TDateTime); 67 | begin 68 | FDate := NewDate; 69 | end; 70 | 71 | { TNewDate } 72 | 73 | function TNewDate.GetText: string; 74 | begin 75 | Result := FormatDateTime ('dddddd', fDate); 76 | end; 77 | 78 | end. 79 | -------------------------------------------------------------------------------- /02_OOP/03_DerivedDates/DerivedDates.dpr: -------------------------------------------------------------------------------- 1 | program DerivedDates; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | ViewDatesForm in 'ViewDatesForm.pas' {DateForm}, 8 | Dates in 'Dates.pas'; 9 | 10 | {$R *.res} 11 | 12 | begin 13 | Application.Initialize; 14 | Application.CreateForm(TDateForm, DateForm); 15 | Application.Run; 16 | end. 17 | -------------------------------------------------------------------------------- /02_OOP/03_DerivedDates/DerivedDates.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/02_OOP/03_DerivedDates/DerivedDates.res -------------------------------------------------------------------------------- /02_OOP/03_DerivedDates/ViewDatesForm.fmx: -------------------------------------------------------------------------------- 1 | object DateForm: TDateForm 2 | Left = 0 3 | Top = 0 4 | Caption = 'ViewDate' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | OnCreate = FormCreate 11 | OnDestroy = FormDestroy 12 | DesignerMasterStyle = 3 13 | object Memo1: TMemo 14 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 15 | DataDetectorTypes = [] 16 | Align = Client 17 | Size.Width = 384.000000000000000000 18 | Size.Height = 214.000000000000000000 19 | Size.PlatformDefault = False 20 | TabOrder = 0 21 | Viewport.Width = 376.000000000000000000 22 | Viewport.Height = 206.000000000000000000 23 | end 24 | object btnToday: TButton 25 | Align = Top 26 | Position.Y = 89.000000000000000000 27 | Size.Width = 384.000000000000000000 28 | Size.Height = 44.000000000000000000 29 | Size.PlatformDefault = False 30 | TabOrder = 1 31 | Text = 'Today' 32 | OnClick = btnTodayClick 33 | end 34 | object btnIncrease: TButton 35 | Align = Top 36 | Position.Y = 133.000000000000000000 37 | Size.Width = 384.000000000000000000 38 | Size.Height = 44.000000000000000000 39 | Size.PlatformDefault = False 40 | TabOrder = 2 41 | Text = 'Increase' 42 | OnClick = btnIncreaseClick 43 | end 44 | object btnDecrease: TButton 45 | Align = Top 46 | Position.Y = 177.000000000000000000 47 | Size.Width = 384.000000000000000000 48 | Size.Height = 44.000000000000000000 49 | Size.PlatformDefault = False 50 | TabOrder = 3 51 | Text = 'Decrease' 52 | OnClick = btnDecreaseClick 53 | end 54 | object LabelDate: TLabel 55 | Align = Top 56 | StyledSettings = [Family, Style, FontColor] 57 | Size.Width = 384.000000000000000000 58 | Size.Height = 89.000000000000000000 59 | Size.PlatformDefault = False 60 | TextSettings.Font.Size = 22.000000000000000000 61 | TextSettings.HorzAlign = Center 62 | Text = 'LabelDate' 63 | end 64 | object btnAdd10: TButton 65 | Align = Top 66 | Position.Y = 221.000000000000000000 67 | Size.Width = 384.000000000000000000 68 | Size.Height = 44.000000000000000000 69 | Size.PlatformDefault = False 70 | TabOrder = 5 71 | Text = 'Add 10' 72 | OnClick = btnAdd10Click 73 | end 74 | object btnSubtract10: TButton 75 | Align = Top 76 | Position.Y = 265.000000000000000000 77 | Size.Width = 384.000000000000000000 78 | Size.Height = 44.000000000000000000 79 | Size.PlatformDefault = False 80 | TabOrder = 6 81 | Text = 'Substract 10' 82 | OnClick = btnSubtract10Click 83 | end 84 | object btnLeapyear: TButton 85 | Align = Top 86 | Position.Y = 309.000000000000000000 87 | Size.Width = 384.000000000000000000 88 | Size.Height = 44.000000000000000000 89 | Size.PlatformDefault = False 90 | TabOrder = 7 91 | Text = 'Is Leap year?' 92 | OnClick = btnLeapyearClick 93 | end 94 | end 95 | -------------------------------------------------------------------------------- /02_OOP/03_DerivedDates/ViewDatesForm.pas: -------------------------------------------------------------------------------- 1 | unit ViewDatesForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, Dates, FMX.Controls.Presentation, FMX.ScrollBox; 9 | 10 | type 11 | TDateForm = class(TForm) 12 | Memo1: TMemo; 13 | btnToday: TButton; 14 | btnIncrease: TButton; 15 | btnDecrease: TButton; 16 | LabelDate: TLabel; 17 | btnAdd10: TButton; 18 | btnSubtract10: TButton; 19 | btnLeapyear: TButton; 20 | procedure btnTodayClick(Sender: TObject); 21 | procedure btnIncreaseClick(Sender: TObject); 22 | procedure FormCreate(Sender: TObject); 23 | procedure FormDestroy(Sender: TObject); 24 | procedure btnLeapyearClick(Sender: TObject); 25 | procedure btnDecreaseClick(Sender: TObject); 26 | procedure btnAdd10Click(Sender: TObject); 27 | procedure btnSubtract10Click(Sender: TObject); 28 | private 29 | ADay: TNewDate; 30 | public 31 | procedure Show (const msg: string); 32 | end; 33 | 34 | var 35 | DateForm: TDateForm; 36 | 37 | implementation 38 | 39 | {$R *.fmx} 40 | 41 | uses 42 | DateUtils; 43 | 44 | procedure TDateForm.btnLeapyearClick(Sender: TObject); 45 | begin 46 | if ADay.LeapYear then 47 | Show ('Leap year: ' + ADay.GetText) 48 | else 49 | Show ('Not a leap year: ' + ADay.GetText); 50 | end; 51 | 52 | procedure TDateForm.btnSubtract10Click(Sender: TObject); 53 | begin 54 | ADay.Decrease (10); 55 | LabelDate.Text := ADay.GetText; 56 | end; 57 | 58 | procedure TDateForm.btnTodayClick(Sender: TObject); 59 | begin 60 | ADay.SetValue(Today); 61 | LabelDate.Text := ADay.GetText; 62 | end; 63 | 64 | procedure TDateForm.FormCreate(Sender: TObject); 65 | begin 66 | // create 67 | ADay := TNewDate.Create; // today 68 | LabelDate.Text := ADay.GetText; 69 | end; 70 | 71 | procedure TDateForm.FormDestroy(Sender: TObject); 72 | begin 73 | ADay.Free; 74 | end; 75 | 76 | procedure TDateForm.btnAdd10Click(Sender: TObject); 77 | begin 78 | ADay.Increase (10); 79 | LabelDate.Text := ADay.GetText; 80 | end; 81 | 82 | procedure TDateForm.btnDecreaseClick(Sender: TObject); 83 | begin 84 | ADay.Decrease; 85 | LabelDate.Text := ADay.GetText; 86 | end; 87 | 88 | procedure TDateForm.btnIncreaseClick(Sender: TObject); 89 | begin 90 | ADay.Increase; 91 | LabelDate.Text := ADay.GetText; 92 | end; 93 | 94 | procedure TDateForm.Show(const Msg: string); 95 | begin 96 | Memo1.Lines.Add(Msg); 97 | end; 98 | 99 | end. 100 | -------------------------------------------------------------------------------- /02_OOP/04_ControlHelper/ControlHelper.dpr: -------------------------------------------------------------------------------- 1 | program ControlHelper; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | HelperForm in 'HelperForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /02_OOP/04_ControlHelper/ControlHelper.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/02_OOP/04_ControlHelper/ControlHelper.res -------------------------------------------------------------------------------- /02_OOP/04_ControlHelper/HelperForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'InterfaceForm' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Button1: TButton 12 | Align = Top 13 | Size.Width = 384.000000000000000000 14 | Size.Height = 44.000000000000000000 15 | Size.PlatformDefault = False 16 | TabOrder = 0 17 | Text = 'Plain Code' 18 | OnClick = Button1Click 19 | end 20 | object Button2: TButton 21 | Align = Top 22 | Position.Y = 44.000000000000000000 23 | Size.Width = 384.000000000000000000 24 | Size.Height = 44.000000000000000000 25 | Size.PlatformDefault = False 26 | TabOrder = 1 27 | Text = 'ListBox Helper' 28 | OnClick = Button2Click 29 | end 30 | object ListBox1: TListBox 31 | Align = Client 32 | Size.Width = 384.000000000000000000 33 | Size.Height = 279.000000000000000000 34 | Size.PlatformDefault = False 35 | TabOrder = 2 36 | DisableFocusEffect = True 37 | Items.Strings = ( 38 | 'One' 39 | 'Two' 40 | 'Three' 41 | 'Four' 42 | 'Five' 43 | 'Six' 44 | 'Seven' 45 | 'Eight' 46 | 'Nine' 47 | 'Ten') 48 | DefaultItemStyles.ItemStyle = '' 49 | DefaultItemStyles.GroupHeaderStyle = '' 50 | DefaultItemStyles.GroupFooterStyle = '' 51 | Viewport.Width = 379.000000000000000000 52 | Viewport.Height = 279.000000000000000000 53 | end 54 | object Memo1: TMemo 55 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 56 | DataDetectorTypes = [] 57 | Align = Bottom 58 | Position.Y = 367.000000000000000000 59 | Size.Width = 384.000000000000000000 60 | Size.Height = 200.000000000000000000 61 | Size.PlatformDefault = False 62 | TabOrder = 3 63 | Viewport.Width = 376.000000000000000000 64 | Viewport.Height = 192.000000000000000000 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /02_OOP/04_ControlHelper/HelperForm.pas: -------------------------------------------------------------------------------- 1 | unit HelperForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.ListBox, FMX.ScrollBox, FMX.Controls.Presentation; 9 | 10 | type 11 | TForm1 = class(TForm) 12 | Button1: TButton; 13 | Button2: TButton; 14 | ListBox1: TListBox; 15 | Memo1: TMemo; 16 | procedure Button1Click(Sender: TObject); 17 | procedure Button2Click(Sender: TObject); 18 | private 19 | { Private declarations } 20 | public 21 | procedure Show (const Text: string); 22 | end; 23 | 24 | var 25 | Form1: TForm1; 26 | 27 | 28 | 29 | implementation 30 | 31 | {$R *.fmx} 32 | 33 | type 34 | TListBoxHelper = class helper for TListBox 35 | function ItemIndexValue: string; 36 | end; 37 | 38 | TMemoHelper = class helper for TMemo 39 | procedure Add (const Text: string); virtual; 40 | end; 41 | 42 | TMyMemo = class (TMemo) 43 | procedure Add (const Text: string); override; 44 | end; 45 | 46 | function TListBoxHelper.ItemIndexValue: string; 47 | begin 48 | Result := ''; 49 | if ItemIndex >= 0 then 50 | Result := Items [ItemIndex]; 51 | end; 52 | 53 | procedure TForm1.Button1Click(Sender: TObject); 54 | begin 55 | if ListBox1.ItemIndex > 0 then 56 | Show (ListBox1.Items[ListBox1.ItemIndex]); 57 | end; 58 | 59 | procedure TForm1.Button2Click(Sender: TObject); 60 | begin 61 | Show (ListBox1.ItemIndexValue); 62 | end; 63 | 64 | procedure TForm1.Show(const Text: string); 65 | begin 66 | Memo1.Add (Text); 67 | end; 68 | 69 | { TMemoHelper } 70 | 71 | procedure TMemoHelper.Add(const Text: string); 72 | begin 73 | Lines.Add(Text); 74 | end; 75 | 76 | { TMyMemo } 77 | 78 | procedure TMyMemo.Add(const Text: string); 79 | begin 80 | Add (Text + ' ' + TimeToStr (Now)); 81 | end; 82 | 83 | end. 84 | -------------------------------------------------------------------------------- /02_OOP/05_FormProperties/FormProperties.dpr: -------------------------------------------------------------------------------- 1 | program FormProperties; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | FormPropertiesForm in 'FormPropertiesForm.pas' {FormProp}; 7 | 8 | {$R *.res} 9 | 10 | begin 11 | Application.Initialize; 12 | Application.CreateForm(TFormProp, FormProp); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /02_OOP/05_FormProperties/FormProperties.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/02_OOP/05_FormProperties/FormProperties.res -------------------------------------------------------------------------------- /02_OOP/05_FormProperties/FormPropertiesForm.fmx: -------------------------------------------------------------------------------- 1 | object FormProp: TFormProp 2 | Left = 0 3 | Top = 0 4 | Caption = 'FormProp' 5 | ClientHeight = 480 6 | ClientWidth = 312 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop, iPhone] 10 | OnMouseDown = FormMouseDown 11 | DesignerMasterStyle = 3 12 | object ToolBarStatus: TToolBar 13 | Align = Bottom 14 | Position.Y = 432.000000000000000000 15 | Size.Width = 312.000000000000000000 16 | Size.Height = 48.000000000000000000 17 | Size.PlatformDefault = False 18 | TabOrder = 0 19 | object LabelStatus: TLabel 20 | Align = Client 21 | Margins.Left = 20.000000000000000000 22 | Margins.Right = 20.000000000000000000 23 | Size.Width = 272.000000000000000000 24 | Size.Height = 48.000000000000000000 25 | Size.PlatformDefault = False 26 | Text = 'Status' 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /02_OOP/05_FormProperties/FormPropertiesForm.pas: -------------------------------------------------------------------------------- 1 | unit FormPropertiesForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Controls.Presentation; 9 | 10 | type 11 | TFormProp = class(TForm) 12 | LabelStatus: TLabel; 13 | ToolBarStatus: TToolBar; 14 | procedure FormMouseDown(Sender: TObject; Button: TMouseButton; 15 | Shift: TShiftState; X, Y: Single); 16 | private 17 | FClicks: Integer; 18 | procedure SetClicks(const Value: Integer); 19 | procedure SetStatusText(const Value: string); 20 | function GetStatusText: string; 21 | { Private declarations } 22 | public 23 | property Clicks: Integer 24 | read FClicks write SetClicks; 25 | property StatusText: string read GetStatusText write SetStatusText; 26 | end; 27 | 28 | var 29 | FormProp: TFormProp; 30 | 31 | implementation 32 | 33 | {$R *.fmx} 34 | 35 | { TForm11 } 36 | 37 | procedure TFormProp.FormMouseDown(Sender: TObject; Button: TMouseButton; 38 | Shift: TShiftState; X, Y: Single); 39 | begin 40 | Clicks := Clicks + 1; 41 | end; 42 | 43 | function TFormProp.GetStatusText: string; 44 | begin 45 | Result := LabelStatus.Text 46 | end; 47 | 48 | procedure TFormProp.SetClicks(const Value: Integer); 49 | begin 50 | FClicks := Value; 51 | StatusText := FClicks.ToString + ' clicks'; 52 | end; 53 | 54 | procedure TFormProp.SetStatusText(const Value: string); 55 | begin 56 | LabelStatus.Text := Value; 57 | end; 58 | 59 | end. 60 | -------------------------------------------------------------------------------- /02_OOP/06_DynamicEvents/DynamicEvents.dpr: -------------------------------------------------------------------------------- 1 | program DynamicEvents; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | DynamicEventsForm in 'DynamicEventsForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TFormDynamic, FormDynamic); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /02_OOP/06_DynamicEvents/DynamicEvents.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/02_OOP/06_DynamicEvents/DynamicEvents.res -------------------------------------------------------------------------------- /02_OOP/06_DynamicEvents/DynamicEventsForm.fmx: -------------------------------------------------------------------------------- 1 | object FormDynamic: TFormDynamic 2 | Left = 0 3 | Top = 0 4 | Caption = 'DynamicEvents' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | OnMouseDown = FormMouseDown 11 | DesignerMasterStyle = 3 12 | object btnTest: TButton 13 | Align = Top 14 | Size.Width = 384.000000000000000000 15 | Size.Height = 44.000000000000000000 16 | Size.PlatformDefault = False 17 | TabOrder = 0 18 | Text = 'Test' 19 | OnClick = btnTestClick 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /02_OOP/06_DynamicEvents/DynamicEventsForm.pas: -------------------------------------------------------------------------------- 1 | unit DynamicEventsForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation; 9 | 10 | type 11 | TFormDynamic = class(TForm) 12 | btnTest: TButton; 13 | procedure btnTestClick(Sender: TObject); 14 | procedure FormMouseDown(Sender: TObject; Button: TMouseButton; 15 | Shift: TShiftState; X, Y: Single); 16 | private 17 | FCounter: Integer; 18 | public 19 | procedure btnTest2Click(Sender: TObject); 20 | procedure btnNewClick(Sender: TObject); 21 | end; 22 | 23 | var 24 | FormDynamic: TFormDynamic; 25 | 26 | implementation 27 | 28 | {$R *.fmx} 29 | 30 | procedure TFormDynamic.btnNewClick(Sender: TObject); 31 | begin 32 | ShowMessage ('You selected ' + (Sender as TButton).Text) 33 | end; 34 | 35 | procedure TFormDynamic.btnTest2Click(Sender: TObject); 36 | begin 37 | ShowMessage ('Test message, again'); 38 | end; 39 | 40 | procedure TFormDynamic.btnTestClick(Sender: TObject); 41 | begin 42 | ShowMessage ('Test message'); 43 | btnTest.OnClick := btnTest2Click; 44 | end; 45 | 46 | procedure TFormDynamic.FormMouseDown(Sender: TObject; Button: TMouseButton; 47 | Shift: TShiftState; X, Y: Single); 48 | var 49 | AButton: TButton; 50 | begin 51 | AButton := TButton.Create(Self); 52 | AButton.Parent := Self; 53 | AButton.SetBounds(X, Y, 100, 40); 54 | Inc (FCounter); 55 | AButton.Text := 'Button' + IntToStr (FCounter); 56 | AButton.OnClick := btnNewClick; 57 | end; 58 | 59 | end. 60 | -------------------------------------------------------------------------------- /02_OOP/07_ClassRef/ClassRef.dpr: -------------------------------------------------------------------------------- 1 | program ClassRef; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | ClassRefForm in 'ClassRefForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /02_OOP/07_ClassRef/ClassRef.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/02_OOP/07_ClassRef/ClassRef.res -------------------------------------------------------------------------------- /02_OOP/07_ClassRef/ClassRefForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'ClassRef' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | OnCreate = FormCreate 11 | DesignerMasterStyle = 3 12 | object GroupBox1: TGroupBox 13 | Align = MostTop 14 | Size.Width = 384.000000000000000000 15 | Size.Height = 70.000000000000000000 16 | Size.PlatformDefault = False 17 | Text = 'Select class' 18 | TabOrder = 0 19 | object RadioButtonButton: TRadioButton 20 | Align = Left 21 | IsChecked = True 22 | Size.Width = 120.000000000000000000 23 | Size.Height = 70.000000000000000000 24 | Size.PlatformDefault = False 25 | TabOrder = 0 26 | Text = 'Btn' 27 | OnChange = RadioButtonButtonChange 28 | end 29 | object RadioButtonRadio: TRadioButton 30 | Align = Client 31 | Size.Width = 144.000000000000000000 32 | Size.Height = 70.000000000000000000 33 | Size.PlatformDefault = False 34 | TabOrder = 1 35 | Text = 'Radio' 36 | OnChange = RadioButtonRadioChange 37 | end 38 | object RadioButtonEdit: TRadioButton 39 | Align = Right 40 | Position.X = 264.000000000000000000 41 | Size.Width = 120.000000000000000000 42 | Size.Height = 70.000000000000000000 43 | Size.PlatformDefault = False 44 | TabOrder = 2 45 | Text = 'Edit' 46 | OnChange = RadioButtonEditChange 47 | end 48 | end 49 | object Layout1: TLayout 50 | Align = Client 51 | HitTest = True 52 | Size.Width = 384.000000000000000000 53 | Size.Height = 497.000000000000000000 54 | Size.PlatformDefault = False 55 | TabOrder = 2 56 | OnMouseDown = Layout1MouseDown 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /02_OOP/07_ClassRef/ClassRefForm.pas: -------------------------------------------------------------------------------- 1 | unit ClassRefForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.Edit; 9 | 10 | type 11 | TControlClass = class of TControl; 12 | 13 | 14 | TForm1 = class(TForm) 15 | GroupBox1: TGroupBox; 16 | RadioButtonButton: TRadioButton; 17 | RadioButtonRadio: TRadioButton; 18 | RadioButtonEdit: TRadioButton; 19 | Layout1: TLayout; 20 | procedure RadioButtonRadioChange(Sender: TObject); 21 | procedure FormCreate(Sender: TObject); 22 | procedure Layout1MouseDown(Sender: TObject; Button: TMouseButton; 23 | Shift: TShiftState; X, Y: Single); 24 | procedure RadioButtonButtonChange(Sender: TObject); 25 | procedure RadioButtonEditChange(Sender: TObject); 26 | private 27 | FControlType: TControlClass; 28 | FControlNo: Integer; 29 | end; 30 | 31 | var 32 | Form1: TForm1; 33 | 34 | 35 | implementation 36 | 37 | {$R *.fmx} 38 | 39 | procedure TForm1.FormCreate(Sender: TObject); 40 | begin 41 | FControlType := TButton; 42 | FControlNo := 0; 43 | end; 44 | 45 | procedure TForm1.Layout1MouseDown(Sender: TObject; Button: TMouseButton; 46 | Shift: TShiftState; X, Y: Single); 47 | var 48 | NewCtrl: TControl; 49 | NewName: String; 50 | begin 51 | // create the control 52 | NewCtrl := FControlType.Create (Self); 53 | // hide it temporarily, to avoid flickering 54 | NewCtrl.Visible := False; 55 | // set parent and position 56 | NewCtrl.Parent := Layout1; 57 | NewCtrl.Position.X := X; 58 | NewCtrl.Position.Y := Y; 59 | // compute the unique name (and text) 60 | Inc (FControlNo); 61 | NewName := FControlType.ClassName + FControlNo.ToString; 62 | Delete (NewName, 1, 1); 63 | NewCtrl.Name := NewName; 64 | // now show it 65 | NewCtrl.Visible := True; 66 | end; 67 | 68 | procedure TForm1.RadioButtonButtonChange(Sender: TObject); 69 | begin 70 | FControlType := TButton; 71 | end; 72 | 73 | procedure TForm1.RadioButtonRadioChange(Sender: TObject); 74 | begin 75 | FControlType := TRadioButton; 76 | end; 77 | 78 | procedure TForm1.RadioButtonEditChange(Sender: TObject); 79 | begin 80 | FControlType := TEdit; 81 | end; 82 | 83 | end. 84 | -------------------------------------------------------------------------------- /02_OOP/08_Intf101/InterfaceForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'InterfaceForm' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Align = Client 15 | Size.Width = 384.000000000000000000 16 | Size.Height = 479.000000000000000000 17 | Size.PlatformDefault = False 18 | TabOrder = 0 19 | Viewport.Width = 376.000000000000000000 20 | Viewport.Height = 471.000000000000000000 21 | end 22 | object Button1: TButton 23 | Align = Top 24 | Size.Width = 384.000000000000000000 25 | Size.Height = 44.000000000000000000 26 | Size.PlatformDefault = False 27 | TabOrder = 1 28 | Text = 'Use with Object' 29 | OnClick = Button1Click 30 | end 31 | object Button2: TButton 32 | Align = Top 33 | Position.Y = 44.000000000000000000 34 | Size.Width = 384.000000000000000000 35 | Size.Height = 44.000000000000000000 36 | Size.PlatformDefault = False 37 | TabOrder = 2 38 | Text = 'Use with Interface' 39 | OnClick = Button2Click 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /02_OOP/08_Intf101/InterfaceForm.pas: -------------------------------------------------------------------------------- 1 | unit InterfaceForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 9 | 10 | type 11 | TForm1 = class(TForm) 12 | Memo1: TMemo; 13 | Button1: TButton; 14 | Button2: TButton; 15 | procedure Button1Click(Sender: TObject); 16 | procedure Button2Click(Sender: TObject); 17 | private 18 | { Private declarations } 19 | public 20 | procedure Show (const msg: string); 21 | end; 22 | 23 | var 24 | Form1: TForm1; 25 | 26 | 27 | type 28 | IWalker = interface 29 | ['{0876F200-AAD3-11D2-8551-CCA30C584521}'] 30 | function Walk: string; 31 | function Run: string; 32 | procedure SetPos (Value: Integer); 33 | function GetPos: Integer; 34 | 35 | property Position: Integer 36 | read GetPos write SetPos; 37 | end; 38 | 39 | IJumper = interface 40 | ['{0876F201-AAD3-11D2-8551-CCA30C584521}'] 41 | function Jump: string; 42 | function Walk: string; 43 | procedure SetPos (Value: Integer); 44 | function GetPos: Integer; 45 | 46 | property Position: Integer 47 | read GetPos write SetPos; 48 | end; 49 | 50 | TRunner = class (TInterfacedObject, IWalker) 51 | private 52 | FPos: Integer; 53 | public 54 | function Walk: string; 55 | function Run: string; 56 | procedure SetPos (Value: Integer); 57 | function GetPos: Integer; 58 | end; 59 | 60 | TJumperImpl = class (TInterfacedObject, IJumper) 61 | private 62 | FPos: Integer; 63 | public 64 | function Jump: string; 65 | function Walk: string; 66 | procedure SetPos (Value: Integer); 67 | function GetPos: Integer; 68 | end; 69 | 70 | 71 | implementation 72 | 73 | {$R *.fmx} 74 | 75 | procedure TForm1.Button1Click(Sender: TObject); 76 | var 77 | runner: TRunner; 78 | begin 79 | runner := TRunner.Create; 80 | try 81 | runner.Run; 82 | Show (runner.GetPos.ToString); 83 | finally 84 | runner.Free; 85 | end; 86 | end; 87 | 88 | procedure TForm1.Button2Click(Sender: TObject); 89 | var 90 | walker: IWalker; 91 | begin 92 | walker := TRunner.Create; 93 | walker.Run; 94 | Show (walker.GetPos.ToString); 95 | end; 96 | 97 | procedure TForm1.Show(const Msg: string); 98 | begin 99 | Memo1.Lines.Add(Msg); 100 | end; 101 | 102 | { TRunner } 103 | 104 | function TRunner.GetPos: Integer; 105 | begin 106 | Result := FPos; 107 | end; 108 | 109 | function TRunner.Run: string; 110 | begin 111 | Inc (FPos, 2); 112 | end; 113 | 114 | procedure TRunner.SetPos(Value: Integer); 115 | begin 116 | FPos := Value; 117 | end; 118 | 119 | function TRunner.Walk: string; 120 | begin 121 | Inc (FPos); 122 | end; 123 | 124 | { TJumperImpl } 125 | 126 | function TJumperImpl.GetPos: Integer; 127 | begin 128 | Result := FPos; 129 | end; 130 | 131 | function TJumperImpl.Jump: string; 132 | begin 133 | Inc (FPos, 3); 134 | end; 135 | 136 | procedure TJumperImpl.SetPos(Value: Integer); 137 | begin 138 | FPos := Value; 139 | end; 140 | 141 | function TJumperImpl.Walk: string; 142 | begin 143 | Inc (FPos); 144 | end; 145 | 146 | initialization 147 | // check we are not leaking objects 148 | ReportMemoryLeaksOnShutdown := True; 149 | 150 | end. 151 | -------------------------------------------------------------------------------- /02_OOP/08_Intf101/Intf101.dpr: -------------------------------------------------------------------------------- 1 | program Intf101; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | InterfaceForm in 'InterfaceForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /02_OOP/08_Intf101/Intf101.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/02_OOP/08_Intf101/Intf101.res -------------------------------------------------------------------------------- /02_OOP/09_IntfDemo/InterfaceForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'InterfaceForm' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | Align = Client 14 | Size.Width = 384.000000000000000000 15 | Size.Height = 391.000000000000000000 16 | Size.PlatformDefault = False 17 | TabOrder = 0 18 | end 19 | object Button1: TButton 20 | Align = Top 21 | Size.Width = 384.000000000000000000 22 | Size.Height = 44.000000000000000000 23 | Size.PlatformDefault = False 24 | TabOrder = 1 25 | Text = 'Runner' 26 | OnClick = Button1Click 27 | end 28 | object Button2: TButton 29 | Align = Top 30 | Position.Y = 44.000000000000000000 31 | Size.Width = 384.000000000000000000 32 | Size.Height = 44.000000000000000000 33 | Size.PlatformDefault = False 34 | TabOrder = 4 35 | Text = 'Jumper' 36 | OnClick = Button2Click 37 | end 38 | object Button3: TButton 39 | Align = Top 40 | Position.Y = 88.000000000000000000 41 | Size.Width = 384.000000000000000000 42 | Size.Height = 44.000000000000000000 43 | Size.PlatformDefault = False 44 | TabOrder = 3 45 | Text = 'Athlete' 46 | OnClick = Button3Click 47 | end 48 | object Button4: TButton 49 | Align = Top 50 | Position.Y = 132.000000000000000000 51 | Size.Width = 384.000000000000000000 52 | Size.Height = 44.000000000000000000 53 | Size.PlatformDefault = False 54 | TabOrder = 2 55 | Text = 'Interface Cast' 56 | OnClick = Button4Click 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /02_OOP/09_IntfDemo/InterfaceForm.pas: -------------------------------------------------------------------------------- 1 | unit InterfaceForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo; 9 | 10 | type 11 | TForm1 = class(TForm) 12 | Memo1: TMemo; 13 | Button1: TButton; 14 | Button2: TButton; 15 | Button3: TButton; 16 | Button4: TButton; 17 | procedure Button1Click(Sender: TObject); 18 | procedure Button2Click(Sender: TObject); 19 | procedure Button3Click(Sender: TObject); 20 | procedure Button4Click(Sender: TObject); 21 | private 22 | { Private declarations } 23 | public 24 | procedure Show (const msg: string); 25 | end; 26 | 27 | var 28 | Form1: TForm1; 29 | 30 | 31 | type 32 | IWalker = interface 33 | ['{0876F200-AAD3-11D2-8551-CCA30C584521}'] 34 | function Walk: string; 35 | function Run: string; 36 | procedure SetPos (Value: Integer); 37 | function GetPos: Integer; 38 | 39 | property Position: Integer 40 | read GetPos write SetPos; 41 | end; 42 | 43 | IJumper = interface 44 | ['{0876F201-AAD3-11D2-8551-CCA30C584521}'] 45 | function Jump: string; 46 | function Walk: string; 47 | procedure SetPos (Value: Integer); 48 | function GetPos: Integer; 49 | 50 | property Position: Integer 51 | read GetPos write SetPos; 52 | end; 53 | 54 | TRunner = class (TInterfacedObject, IWalker) 55 | private 56 | FPos: Integer; 57 | public 58 | function Walk: string; 59 | function Run: string; 60 | procedure SetPos (Value: Integer); 61 | function GetPos: Integer; 62 | end; 63 | 64 | TJumperImpl = class (TAggregatedObject, IJumper) 65 | private 66 | FPos: Integer; 67 | public 68 | function Jump: string; 69 | function Walk: string; 70 | procedure SetPos (Value: Integer); 71 | function GetPos: Integer; 72 | property Position: Integer Read GetPos Write SetPos; 73 | end; 74 | 75 | TMyJumper = class (TInterfacedObject, IJumper) 76 | private 77 | FJumpImpl: TJumperImpl; 78 | public 79 | constructor Create; 80 | destructor Destroy; override; 81 | property Jumper: TJumperImpl 82 | read FJumpImpl implements IJumper; 83 | end; 84 | 85 | TAthlete = class (TInterfacedObject, IWalker, IJumper) 86 | private 87 | FJumpImpl: TJumperImpl; 88 | public 89 | constructor Create; 90 | destructor Destroy; override; 91 | 92 | function Run: string; virtual; 93 | function Walk1: string; virtual; 94 | function IWalker.Walk = Walk1; 95 | procedure SetPos (Value: Integer); 96 | function GetPos: Integer; 97 | 98 | property Jumper: TJumperImpl 99 | read FJumpImpl implements IJumper; 100 | end; 101 | 102 | 103 | implementation 104 | 105 | {$R *.fmx} 106 | 107 | procedure TForm1.Button1Click(Sender: TObject); 108 | var 109 | Intf: IWalker; 110 | begin 111 | Intf := TRunner.Create; 112 | Intf.Position := 0; 113 | Show (Intf.Walk); 114 | Show (Intf.Run); 115 | Show (Intf.Run); 116 | end; 117 | 118 | procedure TForm1.Button2Click(Sender: TObject); 119 | var 120 | Intf: IJumper; 121 | begin 122 | Intf := TMyJumper.Create; 123 | Intf.Position := 0; 124 | Show (Intf.Walk); 125 | Show (Intf.Jump); 126 | Show (Intf.Walk); 127 | end; 128 | 129 | procedure TForm1.Button3Click(Sender: TObject); 130 | var 131 | Intf: IWalker; 132 | begin 133 | Intf := TAthlete.Create; 134 | Intf.Position := 0; 135 | Show (Intf.Walk); 136 | Show (Intf.Run); 137 | Show ((Intf as IJumper).Jump); 138 | end; 139 | 140 | procedure TForm1.Button4Click(Sender: TObject); 141 | var 142 | Intf: IInterface; 143 | WalkIntf: IWalker; 144 | begin 145 | Intf := TAthlete.Create; 146 | if Supports (Intf, IWalker, WalkIntf) then 147 | Show (WalkIntf.Walk); 148 | 149 | if Intf.QueryInterface (IWalker, WalkIntf) = S_OK then 150 | Show (WalkIntf.Walk); 151 | end; 152 | 153 | procedure TForm1.Show(const Msg: string); 154 | begin 155 | Memo1.Lines.Add(Msg); 156 | end; 157 | 158 | 159 | { TRunner } 160 | 161 | function TRunner.GetPos: Integer; 162 | begin 163 | Result := FPos; 164 | end; 165 | 166 | function TRunner.Run: string; 167 | begin 168 | Inc (FPos, 2); 169 | Result := FPos.ToString + ': Run'; 170 | end; 171 | 172 | procedure TRunner.SetPos(Value: Integer); 173 | begin 174 | FPos := Value; 175 | end; 176 | 177 | function TRunner.Walk: string; 178 | begin 179 | Inc (FPos); 180 | Result := FPos.ToString + ': Walk'; 181 | end; 182 | 183 | { TJumperImpl } 184 | 185 | function TJumperImpl.GetPos: Integer; 186 | begin 187 | Result := FPos; 188 | end; 189 | 190 | function TJumperImpl.Jump: string; 191 | begin 192 | Inc (FPos, 3); 193 | Result := FPos.ToString + ': Jump'; 194 | end; 195 | 196 | procedure TJumperImpl.SetPos(Value: Integer); 197 | begin 198 | FPos := Value; 199 | end; 200 | 201 | function TJumperImpl.Walk: string; 202 | begin 203 | Inc (FPos); 204 | Result := FPos.ToString + ': Walk'; 205 | end; 206 | 207 | { TMyJumper } 208 | 209 | constructor TMyJumper.Create; 210 | begin 211 | FJumpImpl := TJumperImpl.Create (self); 212 | end; 213 | 214 | destructor TMyJumper.Destroy; 215 | begin 216 | FJumpImpl.Free; 217 | inherited; 218 | end; 219 | 220 | { TAthlete } 221 | 222 | constructor TAthlete.Create; 223 | begin 224 | FJumpImpl := TJumperImpl.Create (self); 225 | end; 226 | 227 | destructor TAthlete.Destroy; 228 | begin 229 | FJumpImpl.Free; 230 | inherited; 231 | end; 232 | 233 | function TAthlete.GetPos: Integer; 234 | begin 235 | Result := FJumpImpl.Position; 236 | end; 237 | 238 | function TAthlete.Run: string; 239 | begin 240 | FJumpImpl.Position := FJumpImpl.Position + 2; 241 | Result := IntToStr (FJumpImpl.Position) + ': Run'; 242 | end; 243 | 244 | procedure TAthlete.SetPos(Value: Integer); 245 | begin 246 | FJumpImpl.Position := Value; 247 | end; 248 | 249 | function TAthlete.Walk1: string; 250 | begin 251 | FJumpImpl.Position := FJumpImpl.Position + 1; 252 | Result := IntToStr (FJumpImpl.Position) + ': Walk'; 253 | end; 254 | 255 | initialization 256 | // check we are not leaking objects 257 | ReportMemoryLeaksOnShutdown := True; 258 | 259 | end. 260 | -------------------------------------------------------------------------------- /02_OOP/09_IntfDemo/IntfDemo.dpr: -------------------------------------------------------------------------------- 1 | program IntfDemo; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.MobilePreview, 6 | FMX.Forms, 7 | InterfaceForm in 'InterfaceForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /02_OOP/09_IntfDemo/IntfDemo.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/02_OOP/09_IntfDemo/IntfDemo.res -------------------------------------------------------------------------------- /02_OOP/10_AdapterIntf_VCL/Adapter_Demo.dpr: -------------------------------------------------------------------------------- 1 | program Adapter_Demo; 2 | 3 | uses 4 | Forms, 5 | mainform in 'mainform.pas' {FormAdapter}, 6 | adapter_intf in 'adapter_intf.pas'; 7 | 8 | {$R *.RES} 9 | 10 | begin 11 | Application.Initialize; 12 | Application.CreateForm(TFormAdapter, FormAdapter); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /02_OOP/10_AdapterIntf_VCL/Adapter_Demo.dproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {AF8A262A-057F-4526-90E4-846B301BA51C} 4 | Adapter_Demo.dpr 5 | True 6 | Debug 7 | 1 8 | Application 9 | VCL 10 | 18.1 11 | Win32 12 | 13 | 14 | true 15 | 16 | 17 | true 18 | Base 19 | true 20 | 21 | 22 | true 23 | Base 24 | true 25 | 26 | 27 | true 28 | Base 29 | true 30 | 31 | 32 | true 33 | Base 34 | true 35 | 36 | 37 | true 38 | Cfg_2 39 | true 40 | true 41 | 42 | 43 | Adapter_Demo 44 | false 45 | 1033 46 | false 47 | false 48 | false 49 | CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName= 50 | Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;Winapi;$(DCC_Namespace) 51 | false 52 | 00400000 53 | 54 | 55 | true 56 | System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) 57 | $(BDS)\bin\default_app.manifest 58 | 1033 59 | Adapter_Demo_Icon.ico 60 | CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= 61 | true 62 | 63 | 64 | Adapter_Demo_Icon.ico 65 | 66 | 67 | 0 68 | 0 69 | RELEASE;$(DCC_Define) 70 | false 71 | 72 | 73 | true 74 | false 75 | DEBUG;$(DCC_Define) 76 | 77 | 78 | .\$(Platform)\$(Config) 79 | $(BDS)\bin\delphi_PROJECTICON.ico 80 | true 81 | true 82 | CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= 83 | .\$(Platform)\$(Config) 84 | 85 | 86 | 87 | MainSource 88 | 89 | 90 |
FormAdapter
91 |
92 | 93 | 94 | Cfg_2 95 | Base 96 | 97 | 98 | Base 99 | 100 | 101 | Cfg_1 102 | Base 103 | 104 |
105 | 106 | Delphi.Personality.12 107 | 108 | 109 | 110 | 111 | Adapter_Demo.dpr 112 | 113 | 114 | Embarcadero C++Builder Office 2000 Servers Package 115 | Embarcadero C++Builder Office XP Servers Package 116 | Microsoft Office 2000 Sample Automation Server Wrapper Components 117 | Microsoft Office XP Sample Automation Server Wrapper Components 118 | 119 | 120 | 121 | True 122 | False 123 | 124 | 125 | 12 126 | 127 | 128 | 129 |
130 | -------------------------------------------------------------------------------- /02_OOP/10_AdapterIntf_VCL/Adapter_Demo.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/02_OOP/10_AdapterIntf_VCL/Adapter_Demo.res -------------------------------------------------------------------------------- /02_OOP/10_AdapterIntf_VCL/IEdit.pas: -------------------------------------------------------------------------------- 1 | unit IEdit; 2 | 3 | interface 4 | 5 | uses 6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 7 | StdCtrls, adapter_intf; 8 | 9 | type 10 | TEdit = class(StdCtrls.TEdit, ITextAndValue) 11 | private 12 | { Private declarations } 13 | protected 14 | procedure SetText(const Value: string); 15 | procedure SetValue(const Value: Integer); 16 | function GetText: string; 17 | function GetValue: Integer; 18 | public 19 | { Public declarations } 20 | published 21 | { Published declarations } 22 | end; 23 | 24 | implementation 25 | 26 | { TIEdit } 27 | 28 | function TEdit.GetText: string; 29 | begin 30 | Result := Text; 31 | end; 32 | 33 | function TEdit.GetValue: Integer; 34 | begin 35 | Result := StrToIntDef (Text, 0); 36 | end; 37 | 38 | procedure TEdit.SetText(const Value: string); 39 | begin 40 | Text := Value; 41 | end; 42 | 43 | procedure TEdit.SetValue(const Value: Integer); 44 | begin 45 | Text := IntToStr (Value); 46 | end; 47 | 48 | end. 49 | -------------------------------------------------------------------------------- /02_OOP/10_AdapterIntf_VCL/ILabel.pas: -------------------------------------------------------------------------------- 1 | unit ILabel; 2 | 3 | interface 4 | 5 | uses 6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 7 | StdCtrls, adapter_intf; 8 | 9 | type 10 | TLabel = class(StdCtrls.TLabel, ITextAndValue) 11 | private 12 | { Private declarations } 13 | protected 14 | procedure SetText(const Value: string); 15 | procedure SetValue(const Value: Integer); 16 | function GetText: string; 17 | function GetValue: Integer; 18 | public 19 | { Public declarations } 20 | published 21 | { Published declarations } 22 | end; 23 | 24 | implementation 25 | 26 | { TILabel } 27 | 28 | function TLabel.GetText: string; 29 | begin 30 | Result := Caption; 31 | end; 32 | 33 | function TLabel.GetValue: Integer; 34 | begin 35 | Result := StrToIntDef (Caption, 0); 36 | end; 37 | 38 | procedure TLabel.SetText(const Value: string); 39 | begin 40 | Caption := Value; 41 | end; 42 | 43 | procedure TLabel.SetValue(const Value: Integer); 44 | begin 45 | Caption := IntToStr (Value); 46 | end; 47 | 48 | end. 49 | -------------------------------------------------------------------------------- /02_OOP/10_AdapterIntf_VCL/IProgressBar.pas: -------------------------------------------------------------------------------- 1 | unit IProgressBar; 2 | 3 | interface 4 | 5 | uses 6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 7 | ComCtrls, adapter_intf; 8 | 9 | type 10 | TProgressBar = class(ComCtrls.TProgressBar, ITextAndValue) 11 | private 12 | { Private declarations } 13 | protected 14 | procedure SetText(const Value: string); 15 | procedure SetValue(const Value: Integer); 16 | function GetText: string; 17 | function GetValue: Integer; 18 | public 19 | { Public declarations } 20 | published 21 | { Published declarations } 22 | end; 23 | 24 | implementation 25 | 26 | { TIProgressBar } 27 | 28 | function TProgressBar.GetText: string; 29 | begin 30 | Result := IntToStr (Position); 31 | end; 32 | 33 | function TProgressBar.GetValue: Integer; 34 | begin 35 | Result := Position; 36 | end; 37 | 38 | procedure TProgressBar.SetText(const Value: string); 39 | begin 40 | Position := StrToIntDef (Value, 0); 41 | end; 42 | 43 | procedure TProgressBar.SetValue(const Value: Integer); 44 | begin 45 | Position := Value; 46 | end; 47 | 48 | end. 49 | -------------------------------------------------------------------------------- /02_OOP/10_AdapterIntf_VCL/adapter_intf.pas: -------------------------------------------------------------------------------- 1 | unit adapter_intf; 2 | 3 | interface 4 | 5 | type 6 | ITextAndValue = interface 7 | ['{51018CF1-0D3C-488E-81B0-0470B09013EB}'] 8 | procedure SetText(const Value: string); 9 | procedure SetValue(const Value: Integer); 10 | function GetText: string; 11 | function GetValue: Integer; 12 | property Text: string read GetText write SetText; 13 | property Value: Integer read GetValue write SetValue; 14 | end; 15 | 16 | implementation 17 | 18 | end. 19 | -------------------------------------------------------------------------------- /02_OOP/10_AdapterIntf_VCL/mainform.dfm: -------------------------------------------------------------------------------- 1 | object FormAdapter: TFormAdapter 2 | Left = 205 3 | Top = 118 4 | Caption = 'AdapterDemo' 5 | ClientHeight = 333 6 | ClientWidth = 591 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'MS Sans Serif' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | PixelsPerInch = 96 15 | TextHeight = 13 16 | object ILabel1: TLabel 17 | Left = 184 18 | Top = 64 19 | Width = 35 20 | Height = 13 21 | Caption = 'ILabel1' 22 | end 23 | object Label1: TLabel 24 | Left = 184 25 | Top = 32 26 | Width = 32 27 | Height = 13 28 | Caption = 'Label1' 29 | end 30 | object Label2: TLabel 31 | Left = 192 32 | Top = 200 33 | Width = 32 34 | Height = 13 35 | Caption = 'Label2' 36 | end 37 | object Label3: TLabel 38 | Left = 248 39 | Top = 200 40 | Width = 32 41 | Height = 13 42 | Caption = 'Label3' 43 | end 44 | object Label4: TLabel 45 | Left = 312 46 | Top = 200 47 | Width = 32 48 | Height = 13 49 | Caption = 'Label4' 50 | end 51 | object Button1: TButton 52 | Left = 24 53 | Top = 32 54 | Width = 75 55 | Height = 25 56 | Caption = 'all to 50' 57 | TabOrder = 0 58 | OnClick = Button1Click 59 | end 60 | object IEdit1: TEdit 61 | Left = 184 62 | Top = 96 63 | Width = 121 64 | Height = 21 65 | TabOrder = 1 66 | Text = 'IEdit1' 67 | end 68 | object IProgressBar1: TProgressBar 69 | Left = 184 70 | Top = 144 71 | Width = 150 72 | Height = 16 73 | TabOrder = 2 74 | end 75 | object Button2: TButton 76 | Left = 24 77 | Top = 80 78 | Width = 75 79 | Height = 25 80 | Caption = 'class names' 81 | TabOrder = 3 82 | OnClick = Button2Click 83 | end 84 | object Button3: TButton 85 | Left = 24 86 | Top = 120 87 | Width = 75 88 | Height = 25 89 | Caption = 'change edit' 90 | TabOrder = 4 91 | OnClick = Button3Click 92 | end 93 | object Edit1: TEdit 94 | Left = 360 95 | Top = 64 96 | Width = 121 97 | Height = 21 98 | TabOrder = 5 99 | Text = 'Edit1' 100 | end 101 | end 102 | -------------------------------------------------------------------------------- /02_OOP/10_AdapterIntf_VCL/mainform.pas: -------------------------------------------------------------------------------- 1 | unit mainform; 2 | 3 | interface 4 | 5 | uses 6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 7 | ComCtrls, StdCtrls, adapter_intf, IProgressBar, IEdit, ILabel; 8 | 9 | type 10 | TFormAdapter = class(TForm) 11 | Button1: TButton; 12 | ILabel1: TLabel; 13 | IEdit1: TEdit; 14 | IProgressBar1: TProgressBar; 15 | Label1: TLabel; 16 | Button2: TButton; 17 | Label2: TLabel; 18 | Label3: TLabel; 19 | Label4: TLabel; 20 | Button3: TButton; 21 | Edit1: TEdit; 22 | procedure Button1Click(Sender: TObject); 23 | procedure Button2Click(Sender: TObject); 24 | procedure Button3Click(Sender: TObject); 25 | private 26 | { Private declarations } 27 | public 28 | { Public declarations } 29 | end; 30 | 31 | var 32 | FormAdapter: TFormAdapter; 33 | 34 | implementation 35 | 36 | {$R *.DFM} 37 | 38 | procedure TFormAdapter.Button1Click(Sender: TObject); 39 | var 40 | intf: ITextAndValue; 41 | i: integer; 42 | begin 43 | for i := 0 to ComponentCount - 1 do 44 | if Supports (Components [i], ITextAndValue, intf) then 45 | intf.Value := 50; 46 | end; 47 | 48 | procedure TFormAdapter.Button2Click(Sender: TObject); 49 | begin 50 | ShowMessage (Label1.ClassName); 51 | ShowMessage (Label1.ClassParent.ClassName); 52 | end; 53 | 54 | procedure TFormAdapter.Button3Click(Sender: TObject); 55 | var 56 | intf: ITextAndValue; 57 | begin 58 | intf := iedit1; 59 | intf.Value := 20; 60 | end; 61 | 62 | end. 63 | -------------------------------------------------------------------------------- /02_OOP/11_ExceptionFinally/ExceptFinally.dpr: -------------------------------------------------------------------------------- 1 | program ExceptFinally; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | ExceptionForm in 'ExceptionForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /02_OOP/11_ExceptionFinally/ExceptFinally.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/02_OOP/11_ExceptionFinally/ExceptFinally.res -------------------------------------------------------------------------------- /02_OOP/11_ExceptionFinally/ExceptionForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | Align = Client 14 | Size.Width = 384.000000000000000000 15 | Size.Height = 435.000000000000000000 16 | Size.PlatformDefault = False 17 | TabOrder = 0 18 | end 19 | object btnWrong: TButton 20 | Align = Top 21 | Size.Width = 384.000000000000000000 22 | Size.Height = 44.000000000000000000 23 | Size.PlatformDefault = False 24 | TabOrder = 1 25 | Text = 'Wrong' 26 | OnClick = btnWrongClick 27 | end 28 | object btnFinally: TButton 29 | Align = Top 30 | Position.Y = 44.000000000000000000 31 | Size.Width = 384.000000000000000000 32 | Size.Height = 44.000000000000000000 33 | Size.PlatformDefault = False 34 | TabOrder = 3 35 | Text = 'Finally' 36 | OnClick = btnFinallyClick 37 | end 38 | object Button1: TButton 39 | Align = Top 40 | Position.Y = 88.000000000000000000 41 | Size.Width = 384.000000000000000000 42 | Size.Height = 44.000000000000000000 43 | Size.PlatformDefault = False 44 | TabOrder = 2 45 | Text = 'Try Try' 46 | OnClick = Button1Click 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /02_OOP/11_ExceptionFinally/ExceptionForm.pas: -------------------------------------------------------------------------------- 1 | unit ExceptionForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo; 9 | 10 | type 11 | TForm1 = class(TForm) 12 | Memo1: TMemo; 13 | btnWrong: TButton; 14 | btnFinally: TButton; 15 | Button1: TButton; 16 | procedure btnWrongClick(Sender: TObject); 17 | procedure btnFinallyClick(Sender: TObject); 18 | procedure Button1Click(Sender: TObject); 19 | private 20 | { Private declarations } 21 | public 22 | procedure Show (const msg: string); 23 | end; 24 | 25 | var 26 | Form1: TForm1; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | type 33 | EArrayFull = class (Exception); 34 | 35 | procedure AddToArray (i: Integer); 36 | begin 37 | if i > 10 then // not taht this makes much sense... 38 | raise EArrayFull.Create ('Array full'); 39 | end; 40 | 41 | procedure TForm1.btnWrongClick(Sender: TObject); 42 | var 43 | I, J: Integer; 44 | begin 45 | Caption := 'Calculating'; 46 | 47 | J := 0; 48 | // long (and wrong) computation... 49 | for I := 1000 downto 0 do 50 | J := J + J div I; 51 | 52 | Caption := 'Finished'; 53 | Show ('Total: ' + J.ToString); 54 | end; 55 | 56 | procedure TForm1.Button1Click(Sender: TObject); 57 | var 58 | I, J: Integer; 59 | begin 60 | Caption := 'Calculating'; 61 | J := 0; 62 | try try 63 | // long (and wrong) computation... 64 | for I := 1000 downto 0 do 65 | J := J + J div I; 66 | Show ('Total: ' + J.ToString); 67 | except 68 | on E: EDivByZero do 69 | begin 70 | // re-raise the exception with a new message 71 | raise Exception.Create ('Error in Algorithm'); 72 | end; 73 | end; 74 | finally 75 | Caption := 'Finished'; 76 | end; 77 | end; 78 | 79 | procedure TForm1.btnFinallyClick(Sender: TObject); 80 | var 81 | I, J: Integer; 82 | begin 83 | Caption := 'Calculating'; 84 | J := 0; 85 | try 86 | // long (and wrong) computation... 87 | for I := 1000 downto 0 do 88 | J := J + J div I; 89 | Show ('Total: ' + J.ToString); 90 | finally 91 | Caption := 'Finished'; 92 | end; 93 | end; 94 | 95 | procedure TForm1.Show(const Msg: string); 96 | begin 97 | Memo1.Lines.Add(Msg); 98 | end; 99 | 100 | end. 101 | -------------------------------------------------------------------------------- /02_OOP/ProjectGroup2.groupproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {916415F9-1217-4F97-BDC0-D035EC66342A} 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | Default.Personality.12 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /03_Modern/01_KeyValueGeneric_VCL/KeyValueCode.pas: -------------------------------------------------------------------------------- 1 | unit KeyValueCode; 2 | 3 | interface 4 | 5 | type 6 | TKeyValue = class 7 | private 8 | FKey: string; 9 | FValue: T; 10 | procedure SetKey(const Value: string); 11 | procedure SetValue(const Value: T); 12 | public 13 | procedure DoSomething; 14 | property Key: string read FKey write SetKey; 15 | property Value: T read FValue write SetValue; 16 | end; 17 | 18 | implementation 19 | 20 | { TKeyValue } 21 | 22 | procedure TKeyValue.DoSomething; 23 | begin 24 | 25 | end; 26 | 27 | procedure TKeyValue.SetKey(const Value: string); 28 | begin 29 | FKey := Value; 30 | end; 31 | 32 | procedure TKeyValue.SetValue(const Value: T); 33 | begin 34 | FValue := Value; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /03_Modern/01_KeyValueGeneric_VCL/KeyValueForm.dfm: -------------------------------------------------------------------------------- 1 | object Form2: TForm2 2 | Left = 0 3 | Top = 0 4 | Caption = 'KeyValue' 5 | ClientHeight = 225 6 | ClientWidth = 538 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | OnCreate = FormCreate 15 | OnDestroy = FormDestroy 16 | PixelsPerInch = 96 17 | TextHeight = 13 18 | object Button1: TButton 19 | Left = 32 20 | Top = 32 21 | Width = 113 22 | Height = 25 23 | Caption = 'Set KeyValue' 24 | TabOrder = 0 25 | OnClick = Button1Click 26 | end 27 | object Button2: TButton 28 | Left = 32 29 | Top = 64 30 | Width = 113 31 | Height = 25 32 | Caption = 'Change Value' 33 | TabOrder = 1 34 | OnClick = Button2Click 35 | end 36 | object Button3: TButton 37 | Left = 32 38 | Top = 96 39 | Width = 113 40 | Height = 25 41 | Caption = 'Get KeyValue' 42 | TabOrder = 2 43 | OnClick = Button3Click 44 | end 45 | object Button4: TButton 46 | Left = 200 47 | Top = 32 48 | Width = 169 49 | Height = 25 50 | Caption = 'KeyValue ' 51 | TabOrder = 3 52 | OnClick = Button4Click 53 | end 54 | object Button5: TButton 55 | Left = 200 56 | Top = 96 57 | Width = 169 58 | Height = 25 59 | Caption = 'KeyValue ' 60 | TabOrder = 4 61 | OnClick = Button5Click 62 | end 63 | object Button6: TButton 64 | Left = 200 65 | Top = 64 66 | Width = 169 67 | Height = 25 68 | Caption = 'KeyValue ' 69 | TabOrder = 5 70 | OnClick = Button6Click 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /03_Modern/01_KeyValueGeneric_VCL/KeyValueForm.pas: -------------------------------------------------------------------------------- 1 | unit KeyValueForm; 2 | 3 | interface 4 | 5 | uses 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 | Dialogs, StdCtrls, KeyValueCode; 8 | 9 | type 10 | TForm2 = class(TForm) 11 | Button1: TButton; 12 | Button2: TButton; 13 | Button3: TButton; 14 | Button4: TButton; 15 | Button5: TButton; 16 | Button6: TButton; 17 | procedure Button1Click(Sender: TObject); 18 | procedure FormCreate(Sender: TObject); 19 | procedure FormDestroy(Sender: TObject); 20 | procedure Button2Click(Sender: TObject); 21 | procedure Button3Click(Sender: TObject); 22 | procedure Button4Click(Sender: TObject); 23 | procedure Button5Click(Sender: TObject); 24 | procedure Button6Click(Sender: TObject); 25 | private 26 | kv: TKeyValue; 27 | public 28 | { Public declarations } 29 | end; 30 | 31 | var 32 | Form2: TForm2; 33 | 34 | implementation 35 | 36 | {$R *.dfm} 37 | 38 | procedure TForm2.Button1Click(Sender: TObject); 39 | begin 40 | kv.Key := 'mykey'; 41 | kv.Value := Sender as TButton; 42 | end; 43 | 44 | procedure TForm2.Button2Click(Sender: TObject); 45 | begin 46 | kv.Value := Sender as TButton; // was "self" 47 | end; 48 | 49 | procedure TForm2.Button3Click(Sender: TObject); 50 | begin 51 | // ShowMessage ('[' + kv.Key + ',' + kv.Value.ClassName + ']'); 52 | ShowMessage ('[' + kv.Key + ',' + kv.Value.Name + ']'); 53 | end; 54 | 55 | procedure TForm2.Button4Click(Sender: TObject); 56 | var 57 | kvo: TKeyValue; 58 | begin 59 | kvo := TKeyValue.Create; 60 | try 61 | kvo.Key := 'object'; 62 | kvo.Value := Sender; 63 | kvo.Value := self; 64 | ShowMessage ('[' + kvo.Key + ',' + 65 | kvo.Value.ClassName + ']'); 66 | finally 67 | kvo.Free; 68 | end; 69 | end; 70 | 71 | procedure TForm2.Button5Click(Sender: TObject); 72 | var 73 | kvi: TKeyValue; 74 | begin 75 | kvi := TKeyValue.Create; 76 | try 77 | kvi.Key := 'object'; 78 | kvi.Value := 100; 79 | kvi.Value := Left; 80 | ShowMessage ('[' + kvi.Key + ',' + 81 | IntToStr (kvi.Value) + ']'); 82 | finally 83 | kvi.Free; 84 | end; 85 | end; 86 | 87 | procedure TForm2.Button6Click(Sender: TObject); 88 | var 89 | kvo: TKeyValue; 90 | begin 91 | kvo := TKeyValue.Create; 92 | try 93 | kvo.Key := 'object'; 94 | kvo.Value := Sender as TComponent; 95 | kvo.Value := self; 96 | ShowMessage ('[' + kvo.Key + ',' + 97 | kvo.Value.Name + ']'); 98 | finally 99 | kvo.Free; 100 | end; 101 | end; 102 | 103 | procedure TForm2.FormCreate(Sender: TObject); 104 | begin 105 | kv := TKeyValue.Create; 106 | end; 107 | 108 | procedure TForm2.FormDestroy(Sender: TObject); 109 | begin 110 | kv.Free; 111 | end; 112 | 113 | end. 114 | -------------------------------------------------------------------------------- /03_Modern/01_KeyValueGeneric_VCL/KeyValueGeneric.dpr: -------------------------------------------------------------------------------- 1 | program KeyValueGeneric; 2 | 3 | uses 4 | Forms, 5 | KeyValueForm in 'KeyValueForm.pas' {Form2}, 6 | KeyValueCode in 'KeyValueCode.pas'; 7 | 8 | {$R *.res} 9 | 10 | begin 11 | Application.Initialize; 12 | Application.MainFormOnTaskbar := True; 13 | Application.CreateForm(TForm2, Form2); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /03_Modern/01_KeyValueGeneric_VCL/KeyValueGeneric.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/03_Modern/01_KeyValueGeneric_VCL/KeyValueGeneric.res -------------------------------------------------------------------------------- /03_Modern/02_StringListVsDictionary_VCL/ListDictionary_MainForm.dfm: -------------------------------------------------------------------------------- 1 | object FormLists: TFormLists 2 | Left = 0 3 | Top = 0 4 | Caption = 'StringList vs. Dictionary' 5 | ClientHeight = 260 6 | ClientWidth = 619 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = 15 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | OnCreate = FormCreate 15 | OnDestroy = FormDestroy 16 | PixelsPerInch = 96 17 | TextHeight = 15 18 | object Button1: TButton 19 | Left = 11 20 | Top = 30 21 | Width = 57 22 | Height = 19 23 | Margins.Left = 2 24 | Margins.Top = 2 25 | Margins.Right = 2 26 | Margins.Bottom = 2 27 | Caption = 'Button1' 28 | TabOrder = 0 29 | OnClick = Button1Click 30 | end 31 | object Button2: TButton 32 | Left = 317 33 | Top = 30 34 | Width = 57 35 | Height = 19 36 | Margins.Left = 2 37 | Margins.Top = 2 38 | Margins.Right = 2 39 | Margins.Bottom = 2 40 | Caption = 'Button2' 41 | TabOrder = 1 42 | OnClick = Button2Click 43 | end 44 | object Memo1: TMemo 45 | Left = 72 46 | Top = 30 47 | Width = 224 48 | Height = 223 49 | Margins.Left = 2 50 | Margins.Top = 2 51 | Margins.Right = 2 52 | Margins.Bottom = 2 53 | Lines.Strings = ( 54 | 'Memo1') 55 | TabOrder = 2 56 | end 57 | object Memo2: TMemo 58 | Left = 378 59 | Top = 30 60 | Width = 224 61 | Height = 223 62 | Margins.Left = 2 63 | Margins.Top = 2 64 | Margins.Right = 2 65 | Margins.Bottom = 2 66 | Lines.Strings = ( 67 | 'Memo2') 68 | TabOrder = 3 69 | end 70 | object Button3: TButton 71 | Left = 6 72 | Top = 6 73 | Width = 116 74 | Height = 19 75 | Margins.Left = 2 76 | Margins.Top = 2 77 | Margins.Right = 2 78 | Margins.Bottom = 2 79 | Caption = 'Fill Lists' 80 | TabOrder = 4 81 | OnClick = Button3Click 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /03_Modern/02_StringListVsDictionary_VCL/ListDictionary_MainForm.pas: -------------------------------------------------------------------------------- 1 | unit ListDictionary_MainForm; 2 | 3 | interface 4 | 5 | uses 6 | Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 7 | Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Generics.Collections, Vcl.StdCtrls; 8 | 9 | type 10 | TMyObject = class 11 | private 12 | FValue: Integer; 13 | procedure SetValue(const Value: Integer); 14 | public 15 | property Value: Integer read FValue write SetValue; 16 | end; 17 | 18 | TFormLists = class(TForm) 19 | Button1: TButton; 20 | Button2: TButton; 21 | Memo1: TMemo; 22 | Memo2: TMemo; 23 | Button3: TButton; 24 | procedure Button3Click(Sender: TObject); 25 | procedure FormCreate(Sender: TObject); 26 | procedure FormDestroy(Sender: TObject); 27 | procedure Button1Click(Sender: TObject); 28 | procedure Button2Click(Sender: TObject); 29 | private 30 | sList: TStringList; 31 | 32 | // changed code (in Frankfurt) to use the specific TObjectDictionary class 33 | // which allows objects ownership for either values or keys 34 | 35 | sDict: {TDictionary} TObjectDictionary; 36 | // procedure ValueNotify(Sender: TObject; const Item: TMyObject; 37 | // Action: TCollectionNotification); 38 | public 39 | { Public declarations } 40 | end; 41 | 42 | var 43 | FormLists: TFormLists; 44 | 45 | implementation 46 | 47 | {$R *.dfm} 48 | 49 | uses 50 | Diagnostics; 51 | 52 | function RandomName: string; 53 | var 54 | i: Integer; 55 | begin 56 | Result := ''; 57 | for I := 1 to 30 + Random (50) do 58 | Result := Result + Char (Ord('a') + Random (26)); 59 | end; 60 | 61 | procedure TFormLists.Button1Click(Sender: TObject); 62 | var 63 | sw: TStopwatch; 64 | I: Integer; 65 | aName: string; 66 | anIndex: Integer; 67 | anObject: TMyObject; 68 | theTotal: integer; 69 | begin 70 | sw.Reset; 71 | sw.Start; 72 | 73 | theTotal := 0; 74 | for I := 0 to sList.Count -1 do 75 | begin 76 | aName := sList[I]; 77 | // now search for it 78 | anIndex := sList.IndexOf (aName); 79 | // get the object 80 | anObject := sList.Objects [anIndex] as TMyObject; 81 | Inc (theTotal, anObject.Value); 82 | end; 83 | 84 | sw.Stop; 85 | memo1.Lines.Add ('Total: ' + IntToStr (theTotal)); 86 | memo1.Lines.Add ('StringList: ' + IntToStr (sw.ElapsedMilliseconds)); 87 | end; 88 | 89 | procedure TFormLists.Button2Click(Sender: TObject); 90 | var 91 | sw: TStopwatch; 92 | I: Integer; 93 | aName: string; 94 | anObject: TMyObject; 95 | theTotal: integer; 96 | begin 97 | sw.Reset; 98 | sw.Start; 99 | 100 | theTotal := 0; 101 | for I := 0 to sList.Count -1 do 102 | begin 103 | aName := sList[I]; 104 | // get the object 105 | anObject := sDict.Items [aName]; 106 | Inc (theTotal, anObject.Value); 107 | end; 108 | 109 | sw.Stop; 110 | memo2.Lines.Add ('Total: ' + IntToStr (theTotal)); 111 | memo2.Lines.Add ('Dictionary: ' + IntToStr (sw.ElapsedMilliseconds)); 112 | end; 113 | 114 | procedure TFormLists.Button3Click(Sender: TObject); 115 | var 116 | I: Integer; 117 | aName: string; 118 | anObject: TMyObject; 119 | begin 120 | // else insertion is very slow 121 | sList.Sorted := False; 122 | 123 | for I := 1 to 500000 do // half million 124 | begin 125 | aName := RandomName; 126 | anObject := TMyObject.Create; 127 | anObject.Value := Random (200); 128 | sList.AddObject (aName, anObject); 129 | sDict.Add (aName, anObject); 130 | if (I mod 1000) = 0 then 131 | Application.ProcessMessages; 132 | end; 133 | Caption := Caption + ' - ' + IntToStr (sList.Count); 134 | 135 | // else insertion is very slow 136 | sList.Sorted := True; 137 | end; 138 | 139 | procedure TFormLists.FormCreate(Sender: TObject); 140 | begin 141 | sList := TStringList.Create; 142 | sDict := {TDictionary} TObjectDictionary. 143 | Create ([doOwnsValues]); 144 | // sDict.OnValueNotify := ValueNotify; 145 | randomize; 146 | end; 147 | 148 | procedure TFormLists.FormDestroy(Sender: TObject); 149 | begin 150 | sList.Free; 151 | sDict.Free; 152 | end; 153 | 154 | //procedure TForm1.ValueNotify(Sender: TObject; const Item: TMyObject; 155 | // Action: TCollectionNotification); 156 | //begin 157 | // if Action = cnRemoved then 158 | // Item.Free; 159 | //end; 160 | 161 | { TMyObject } 162 | 163 | procedure TMyObject.SetValue(const Value: Integer); 164 | begin 165 | FValue := Value; 166 | end; 167 | 168 | initialization 169 | ReportMemoryLeaksOnShutdown := True; 170 | 171 | end. 172 | -------------------------------------------------------------------------------- /03_Modern/02_StringListVsDictionary_VCL/StringListVsDictionary.dpr: -------------------------------------------------------------------------------- 1 | program StringListVsDictionary; 2 | 3 | uses 4 | Vcl.Forms, 5 | ListDictionary_MainForm in 'ListDictionary_MainForm.pas' {FormLists}; 6 | 7 | {$R *.res} 8 | 9 | begin 10 | Application.Initialize; 11 | Application.MainFormOnTaskbar := True; 12 | Application.CreateForm(TFormLists, FormLists); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /03_Modern/02_StringListVsDictionary_VCL/StringListVsDictionary.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/03_Modern/02_StringListVsDictionary_VCL/StringListVsDictionary.res -------------------------------------------------------------------------------- /03_Modern/03_GenericMethod/GenericForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Align = Client 15 | Size.Width = 384.000000000000000000 16 | Size.Height = 479.000000000000000000 17 | Size.PlatformDefault = False 18 | TabOrder = 0 19 | Viewport.Width = 376.000000000000000000 20 | Viewport.Height = 471.000000000000000000 21 | end 22 | object Button1: TButton 23 | Align = Top 24 | Size.Width = 384.000000000000000000 25 | Size.Height = 44.000000000000000000 26 | Size.PlatformDefault = False 27 | TabOrder = 1 28 | Text = 'Correct Calls' 29 | OnClick = Button1Click 30 | end 31 | object Button2: TButton 32 | Align = Top 33 | Position.Y = 44.000000000000000000 34 | Size.Width = 384.000000000000000000 35 | Size.Height = 44.000000000000000000 36 | Size.PlatformDefault = False 37 | TabOrder = 2 38 | Text = 'Wrong Calls' 39 | OnClick = Button2Click 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /03_Modern/03_GenericMethod/GenericForm.pas: -------------------------------------------------------------------------------- 1 | unit GenericForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 9 | 10 | type 11 | TForm1 = class(TForm) 12 | Memo1: TMemo; 13 | Button1: TButton; 14 | Button2: TButton; 15 | procedure Button1Click(Sender: TObject); 16 | procedure Button2Click(Sender: TObject); 17 | private 18 | { Private declarations } 19 | public 20 | procedure Show (const msg: string); 21 | end; 22 | 23 | var 24 | Form1: TForm1; 25 | 26 | implementation 27 | 28 | {$R *.fmx} 29 | 30 | uses 31 | TypInfo; 32 | 33 | type 34 | TGenericFunction = class 35 | public 36 | function WithParam (t1: T): string; 37 | end; 38 | 39 | procedure TForm1.Button1Click(Sender: TObject); 40 | var 41 | gf: TGenericFunction; 42 | begin 43 | gf := TGenericFunction.Create; 44 | try 45 | Show (gf.WithParam('foo')); 46 | Show (gf.WithParam (122)); 47 | Show (gf.WithParam('hello')); 48 | Show (gf.WithParam (122)); 49 | Show (gf.WithParam(Button1)); 50 | Show (gf.WithParam(Button1)); 51 | finally 52 | gf.Free; 53 | end; 54 | end; 55 | 56 | procedure TForm1.Button2Click(Sender: TObject); 57 | var 58 | gf: TGenericFunction; 59 | begin 60 | gf := TGenericFunction.Create; 61 | try 62 | // these 3 are all wrong 63 | // Show (gf.WithParam('foo')); 64 | // Show (gf.WithParam (122)); 65 | // Show (gf.WithParam(self)); 66 | finally 67 | gf.Free; 68 | end; 69 | end; 70 | 71 | procedure TForm1.Show(const Msg: string); 72 | begin 73 | Memo1.Lines.Add(Msg); 74 | end; 75 | 76 | { TGenericFunction } 77 | 78 | function TGenericFunction.WithParam(t1: T): string; 79 | begin 80 | Result := GetTypeName (TypeInfo (T)); 81 | // if IsManagedType (T) then 82 | // Result := Result + ' managed'; 83 | end; 84 | 85 | end. 86 | -------------------------------------------------------------------------------- /03_Modern/03_GenericMethod/GenericMethod.dpr: -------------------------------------------------------------------------------- 1 | program GenericMethod; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | GenericForm in 'GenericForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /03_Modern/03_GenericMethod/GenericMethod.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/03_Modern/03_GenericMethod/GenericMethod.res -------------------------------------------------------------------------------- /03_Modern/04_RttiAccess/RttiAccess.dpr: -------------------------------------------------------------------------------- 1 | program RttiAccess; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | RttiForm in 'RttiForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /03_Modern/04_RttiAccess/RttiAccess.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/03_Modern/04_RttiAccess/RttiAccess.res -------------------------------------------------------------------------------- /03_Modern/04_RttiAccess/RttiForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'TypesList' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object btnReadValues: TButton 12 | Align = Top 13 | Size.Width = 384.000000000000000000 14 | Size.Height = 44.000000000000000000 15 | Size.PlatformDefault = False 16 | TabOrder = 1 17 | Text = 'Read Values' 18 | OnClick = btnReadValuesClick 19 | end 20 | object btnInvoke: TButton 21 | Align = Top 22 | Position.Y = 44.000000000000000000 23 | Size.Width = 384.000000000000000000 24 | Size.Height = 44.000000000000000000 25 | Size.PlatformDefault = False 26 | TabOrder = 0 27 | Text = 'Invoke' 28 | OnClick = btnInvokeClick 29 | end 30 | object Memo1: TMemo 31 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 32 | DataDetectorTypes = [] 33 | Align = Client 34 | Size.Width = 384.000000000000000000 35 | Size.Height = 479.000000000000000000 36 | Size.PlatformDefault = False 37 | TabOrder = 2 38 | Viewport.Width = 376.000000000000000000 39 | Viewport.Height = 471.000000000000000000 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /03_Modern/04_RttiAccess/RttiForm.pas: -------------------------------------------------------------------------------- 1 | unit RttiForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.ListBox, FMX.ListView.Types, FMX.ListView, 9 | FMX.ScrollBox, FMX.Controls.Presentation; 10 | 11 | type 12 | TForm1 = class(TForm) 13 | btnReadValues: TButton; 14 | btnInvoke: TButton; 15 | Memo1: TMemo; 16 | procedure btnReadValuesClick(Sender: TObject); 17 | procedure btnInvokeClick(Sender: TObject); 18 | private 19 | { Private declarations } 20 | public 21 | procedure Show (Message: string); 22 | end; 23 | 24 | var 25 | Form1: TForm1; 26 | 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | uses 33 | System.Rtti; 34 | 35 | procedure TForm1.btnInvokeClick(Sender: TObject); 36 | var 37 | context: TRttiContext; 38 | aType: TRttiType; 39 | aMethod: TRttiMethod; 40 | theValues: array of TValue; 41 | aValue: TValue; 42 | begin 43 | aType := context.GetType(TButton); 44 | aMethod := aType.GetMethod('ToString'); 45 | theValues := []; 46 | aValue := aMethod.Invoke(Sender, theValues); 47 | Show(aValue.AsString); 48 | 49 | aType := context.GetType(TForm1); 50 | aMethod := aType.GetMethod('Show'); 51 | SetLength (theValues, 1); 52 | theValues[0] := 'Hello'; 53 | aMethod.Invoke(self, theValues); 54 | end; 55 | 56 | procedure TForm1.btnReadValuesClick(Sender: TObject); 57 | var 58 | context: TRttiContext; 59 | aType: TRttiType; 60 | aProperty: TRttiProperty; 61 | aValue: TValue; 62 | aField: TRttiField; 63 | begin 64 | aType := context.GetType(TButton); 65 | aProperty := aType.GetProperty('Text'); 66 | aValue := aProperty.GetValue(Sender); 67 | Show (aValue.AsString); 68 | 69 | aField := aType.GetField('FDesignInfo'); 70 | aValue := aField.GetValue(Sender); 71 | Show (aValue.AsInteger.ToString); 72 | end; 73 | 74 | procedure TForm1.Show(Message: string); 75 | begin 76 | Memo1.Lines.Add(Message); 77 | end; 78 | 79 | end. 80 | -------------------------------------------------------------------------------- /03_Modern/05_TypesList/TypeInfoForm.fmx: -------------------------------------------------------------------------------- 1 | object FormTypeInfo: TFormTypeInfo 2 | Left = 0 3 | Top = 0 4 | Caption = 'Type Details' 5 | ClientHeight = 474 6 | ClientWidth = 316 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object TabControl1: TTabControl 12 | Align = Client 13 | Size.Width = 316.000000000000000000 14 | Size.Height = 434.000000000000000000 15 | Size.PlatformDefault = False 16 | TabIndex = 2 17 | TabOrder = 1 18 | TabPosition = PlatformDefault 19 | Sizes = ( 20 | 316s 21 | 408s 22 | 316s 23 | 408s 24 | 316s 25 | 408s) 26 | object TabItem1: TTabItem 27 | CustomIcon = < 28 | item 29 | end> 30 | IsSelected = False 31 | Size.Width = 74.000000000000000000 32 | Size.Height = 26.000000000000000000 33 | Size.PlatformDefault = False 34 | StyleLookup = '' 35 | TabOrder = 0 36 | Text = 'Properties' 37 | ExplicitSize.cx = 74.000000000000000000 38 | ExplicitSize.cy = 24.000000000000000000 39 | object LVProperties: TListView 40 | ItemAppearanceClassName = 'TListItemAppearance' 41 | ItemEditAppearanceClassName = 'TListItemShowCheckAppearance' 42 | HeaderAppearanceClassName = 'TListHeaderObjects' 43 | FooterAppearanceClassName = 'TListHeaderObjects' 44 | Align = Client 45 | Size.Width = 316.000000000000000000 46 | Size.Height = 408.000000000000000000 47 | Size.PlatformDefault = False 48 | TabOrder = 0 49 | end 50 | end 51 | object TabItem2: TTabItem 52 | CustomIcon = < 53 | item 54 | end> 55 | IsSelected = False 56 | Size.Width = 68.000000000000000000 57 | Size.Height = 26.000000000000000000 58 | Size.PlatformDefault = False 59 | StyleLookup = '' 60 | TabOrder = 0 61 | Text = 'Methods' 62 | ExplicitSize.cx = 67.000000000000000000 63 | ExplicitSize.cy = 24.000000000000000000 64 | object LVMethods: TListView 65 | ItemAppearanceClassName = 'TListItemAppearance' 66 | ItemEditAppearanceClassName = 'TListItemShowCheckAppearance' 67 | HeaderAppearanceClassName = 'TListHeaderObjects' 68 | FooterAppearanceClassName = 'TListHeaderObjects' 69 | Align = Client 70 | Size.Width = 316.000000000000000000 71 | Size.Height = 408.000000000000000000 72 | Size.PlatformDefault = False 73 | TabOrder = 0 74 | end 75 | end 76 | object TabItem3: TTabItem 77 | CustomIcon = < 78 | item 79 | end> 80 | IsSelected = True 81 | Size.Width = 51.000000000000000000 82 | Size.Height = 26.000000000000000000 83 | Size.PlatformDefault = False 84 | StyleLookup = '' 85 | TabOrder = 0 86 | Text = 'Fields' 87 | ExplicitSize.cx = 50.000000000000000000 88 | ExplicitSize.cy = 24.000000000000000000 89 | object LVFields: TListView 90 | ItemAppearanceClassName = 'TListItemAppearance' 91 | ItemEditAppearanceClassName = 'TListItemDeleteAppearance' 92 | HeaderAppearanceClassName = 'TListHeaderObjects' 93 | FooterAppearanceClassName = 'TListHeaderObjects' 94 | Align = Client 95 | Size.Width = 316.000000000000000000 96 | Size.Height = 408.000000000000000000 97 | Size.PlatformDefault = False 98 | TabOrder = 0 99 | end 100 | end 101 | end 102 | object ToolBar1: TToolBar 103 | Size.Width = 316.000000000000000000 104 | Size.Height = 40.000000000000000000 105 | Size.PlatformDefault = False 106 | TabOrder = 2 107 | object SpeedButton1: TSpeedButton 108 | Align = Right 109 | Position.X = 272.000000000000000000 110 | Size.Width = 44.000000000000000000 111 | Size.Height = 40.000000000000000000 112 | Size.PlatformDefault = False 113 | StyleLookup = 'priortoolbutton' 114 | end 115 | object LabelType: TLabel 116 | Align = Client 117 | Size.Width = 272.000000000000000000 118 | Size.Height = 40.000000000000000000 119 | Size.PlatformDefault = False 120 | TextSettings.HorzAlign = Center 121 | Text = 'Type' 122 | end 123 | end 124 | end 125 | -------------------------------------------------------------------------------- /03_Modern/05_TypesList/TypeInfoForm.pas: -------------------------------------------------------------------------------- 1 | unit TypeInfoForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.RTTI, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, 8 | FMX.ListView.Types, FMX.ListView, FMX.TabControl, FMX.StdCtrls, 9 | FMX.ListView.Appearances, FMX.ListView.Adapters.Base, 10 | FMX.Controls.Presentation; 11 | 12 | type 13 | TFormTypeInfo = class(TForm) 14 | TabControl1: TTabControl; 15 | TabItem1: TTabItem; 16 | TabItem2: TTabItem; 17 | TabItem3: TTabItem; 18 | LVProperties: TListView; 19 | LVMethods: TListView; 20 | LVFields: TListView; 21 | ToolBar1: TToolBar; 22 | SpeedButton1: TSpeedButton; 23 | LabelType: TLabel; 24 | private 25 | { Private declarations } 26 | public 27 | procedure Clear; 28 | procedure ShowTypeDetails (typename: string); 29 | end; 30 | 31 | var 32 | FormTypeInfo: TFormTypeInfo; 33 | 34 | implementation 35 | 36 | {$R *.fmx} 37 | 38 | uses 39 | System.TypInfo; 40 | 41 | { TFormTypeInfo } 42 | 43 | procedure TFormTypeInfo.Clear; 44 | begin 45 | LVProperties.Items.Clear; 46 | LVMethods.Items.Clear; 47 | LVFields.Items.Clear; 48 | end; 49 | 50 | function VisibilityToken (mv: TMemberVisibility): string; 51 | begin 52 | case mv of 53 | mvPrivate: Result := '[pri]'; 54 | mvProtected: Result := '[pro]'; 55 | mvPublic: Result := '[pub]'; 56 | mvPublished: Result := '[pbl]'; 57 | else 58 | Result := '[und]'; 59 | end; 60 | end; 61 | 62 | procedure TFormTypeInfo.ShowTypeDetails(typename: string); 63 | var 64 | aContext: TRttiContext; 65 | aType: TRttiType; 66 | aProperty: TRttiProperty; 67 | aMethod: TRttiMethod; 68 | aField: TRttiField; 69 | begin 70 | aType := aContext.FindType(typename); 71 | if not Assigned(aType) then 72 | Exit; 73 | 74 | LabelType.Text := aType.QualifiedName; 75 | for aProperty in atype.GetProperties do 76 | FormTypeInfo.LVProperties.Items.Add.Text := aProperty.Name + 77 | ': ' + aProperty.PropertyType.Name + ' ' + 78 | VisibilityToken (aProperty.Visibility); 79 | for aMethod in atype.GetMethods do 80 | LVMethods.Items.Add.Text := aMethod.Name + ' ' + 81 | VisibilityToken (aMethod.Visibility); 82 | for aField in aType.GetFields do 83 | LVFields.Items.Add.Text := aField.Name + ': ' + 84 | aField.FieldType.Name + ' ' + 85 | VisibilityToken (aField.Visibility); 86 | 87 | end; 88 | 89 | end. 90 | -------------------------------------------------------------------------------- /03_Modern/05_TypesList/TypesForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'TypesList' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object btnTypesList: TButton 12 | Align = Top 13 | Size.Width = 384.000000000000000000 14 | Size.Height = 44.000000000000000000 15 | Size.PlatformDefault = False 16 | TabOrder = 0 17 | Text = 'Types List' 18 | OnClick = btnTypesListClick 19 | end 20 | object ListView1: TListView 21 | ItemAppearanceClassName = 'TListItemAppearance' 22 | ItemEditAppearanceClassName = 'TListItemShowCheckAppearance' 23 | HeaderAppearanceClassName = 'TListHeaderObjects' 24 | FooterAppearanceClassName = 'TListHeaderObjects' 25 | Align = Client 26 | Size.Width = 384.000000000000000000 27 | Size.Height = 523.000000000000000000 28 | Size.PlatformDefault = False 29 | TabOrder = 1 30 | OnItemClick = ListView1ItemClick 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /03_Modern/05_TypesList/TypesForm.pas: -------------------------------------------------------------------------------- 1 | unit TypesForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.ListBox, FMX.ListView.Types, FMX.ListView, 9 | FMX.ListView.Appearances, FMX.ListView.Adapters.Base, 10 | FMX.Controls.Presentation; 11 | 12 | type 13 | TForm1 = class(TForm) 14 | btnTypesList: TButton; 15 | ListView1: TListView; 16 | procedure btnTypesListClick(Sender: TObject); 17 | procedure ListView1ItemClick(const Sender: TObject; 18 | const AItem: TListViewItem); 19 | private 20 | { Private declarations } 21 | public 22 | end; 23 | 24 | var 25 | Form1: TForm1; 26 | 27 | 28 | 29 | implementation 30 | 31 | {$R *.fmx} 32 | 33 | uses 34 | System.Rtti, TypeInfoForm; 35 | 36 | procedure TForm1.btnTypesListClick(Sender: TObject); 37 | var 38 | aContext: TRttiContext; 39 | theTypes: TArray; 40 | sList: TStringList; 41 | aType: TRttiType; 42 | sTypeName: string; 43 | begin 44 | ListView1.Items.Clear; 45 | sList := TStringList.Create; 46 | try 47 | theTypes := aContext.GetTypes; 48 | for aType in theTypes do 49 | if aType.IsInstance then 50 | sList.Add(aType.QualifiedName); 51 | sList.Sort; 52 | ListView1.BeginUpdate; 53 | try 54 | for sTypeName in sList do 55 | (ListView1.Items.Add).Text := sTypeName; 56 | finally 57 | ListView1.EndUpdate; 58 | end; 59 | finally 60 | sList.Free; 61 | end; 62 | end; 63 | 64 | procedure TForm1.ListView1ItemClick(const Sender: TObject; 65 | const AItem: TListViewItem); 66 | begin 67 | FormTypeInfo.Clear; 68 | FormTypeInfo.ShowTypeDetails(AItem.Text); 69 | FormTypeInfo.Show; 70 | end; 71 | 72 | end. 73 | -------------------------------------------------------------------------------- /03_Modern/05_TypesList/TypesList.dpr: -------------------------------------------------------------------------------- 1 | program TypesList; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | TypesForm in 'TypesForm.pas' {Form1}, 8 | TypeInfoForm in 'TypeInfoForm.pas' {FormTypeInfo}; 9 | 10 | {$R *.res} 11 | 12 | begin 13 | Application.Initialize; 14 | Application.CreateForm(TForm1, Form1); 15 | Application.CreateForm(TFormTypeInfo, FormTypeInfo); 16 | Application.Run; 17 | end. 18 | -------------------------------------------------------------------------------- /03_Modern/05_TypesList/TypesList.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/03_Modern/05_TypesList/TypesList.res -------------------------------------------------------------------------------- /03_Modern/06_RttiAttrib_VCL/RttiAttrib.dpr: -------------------------------------------------------------------------------- 1 | program RttiAttrib; 2 | 3 | uses 4 | Forms, 5 | RttiAttribMainForm in 'RttiAttribMainForm.pas' {Form39}; 6 | 7 | {$R *.res} 8 | 9 | begin 10 | Application.Initialize; 11 | Application.MainFormOnTaskbar := True; 12 | Application.CreateForm(TForm39, Form39); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /03_Modern/06_RttiAttrib_VCL/RttiAttrib.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/03_Modern/06_RttiAttrib_VCL/RttiAttrib.res -------------------------------------------------------------------------------- /03_Modern/06_RttiAttrib_VCL/RttiAttribMainForm.dfm: -------------------------------------------------------------------------------- 1 | object Form39: TForm39 2 | Left = 0 3 | Top = 0 4 | Caption = 'RttiAttrib' 5 | ClientHeight = 292 6 | ClientWidth = 554 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | PixelsPerInch = 96 15 | TextHeight = 13 16 | object btnMethods: TButton 17 | Left = 26 18 | Top = 76 19 | Width = 105 20 | Height = 25 21 | Caption = 'btnMethods' 22 | TabOrder = 0 23 | OnClick = btnMethodsClick 24 | end 25 | object Memo1: TMemo 26 | Left = 152 27 | Top = 26 28 | Width = 385 29 | Height = 239 30 | TabOrder = 1 31 | end 32 | object btnClassAttribs: TButton 33 | Left = 26 34 | Top = 24 35 | Width = 105 36 | Height = 25 37 | Caption = 'btnClassAttribs' 38 | TabOrder = 2 39 | OnClick = btnClassAttribsClick 40 | end 41 | object btnInvokeIfZero: TButton 42 | Left = 26 43 | Top = 128 44 | Width = 105 45 | Height = 25 46 | Caption = 'btnInvokeIfZero' 47 | TabOrder = 3 48 | OnClick = btnInvokeIfZeroClick 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /03_Modern/06_RttiAttrib_VCL/RttiAttribMainForm.pas: -------------------------------------------------------------------------------- 1 | unit RttiAttribMainForm; 2 | 3 | interface 4 | 5 | uses 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 | Dialogs, StdCtrls; 8 | 9 | type 10 | TForm39 = class(TForm) 11 | btnMethods: TButton; 12 | Memo1: TMemo; 13 | btnClassAttribs: TButton; 14 | btnInvokeIfZero: TButton; 15 | procedure btnMethodsClick(Sender: TObject); 16 | procedure btnClassAttribsClick(Sender: TObject); 17 | procedure btnInvokeIfZeroClick(Sender: TObject); 18 | private 19 | { Private declarations } 20 | public 21 | procedure Log (const strMsg: string); 22 | end; 23 | 24 | type 25 | SimpleAttribute = class(TCustomAttribute) 26 | end; 27 | 28 | ValueAttribute = class(TCustomAttribute) 29 | private 30 | FValue: Integer; 31 | public 32 | constructor Create(N: Integer); 33 | property Value: Integer read FValue write FValue; 34 | end; 35 | 36 | type 37 | // Uncommenting [More] causes a warning and is ignored 38 | [Simple][Value(22)] // [More] 39 | TMyClass = class(TObject) 40 | public 41 | [Simple] 42 | procedure One; 43 | [Value(0)] 44 | procedure Two; 45 | 46 | procedure Three; 47 | end; 48 | 49 | var 50 | Form39: TForm39; 51 | 52 | implementation 53 | 54 | {$R *.dfm} 55 | 56 | uses 57 | Rtti; 58 | 59 | { FooAttribute } 60 | 61 | constructor ValueAttribute.Create(N: Integer); 62 | begin 63 | FValue := N; 64 | end; 65 | 66 | type 67 | TCustomAttributeClass = class of TCustomAttribute; 68 | 69 | function HasAttribute (aMethod: TRttiMethod; attribClass: TCustomAttributeClass): Boolean; 70 | var 71 | attributes: TArray; 72 | attrib: TCustomAttribute; 73 | begin 74 | Result := False; 75 | attributes := aMethod.GetAttributes; 76 | for attrib in attributes do 77 | if attrib.InheritsFrom (attribClass) then 78 | Exit (True); 79 | end; 80 | 81 | procedure TForm39.btnInvokeIfZeroClick(Sender: TObject); 82 | var 83 | context: TRttiContext; 84 | aType: TRttiType; 85 | aMethod: TRttiMethod; 86 | aTarget: TMyClass; 87 | zeroParams: array of TValue; 88 | begin 89 | aTarget := TMyClass.Create; 90 | try 91 | aType := context.GetType(aTarget.ClassType); 92 | for aMethod in aType.GetMethods do 93 | if HasAttribute (aMethod, SimpleAttribute) then 94 | aMethod.Invoke(aTarget, zeroParams); 95 | finally 96 | aTarget.Free; 97 | end; 98 | end; 99 | 100 | procedure TForm39.btnMethodsClick(Sender: TObject); 101 | var 102 | context: TRttiContext; 103 | aType: TRttiType; 104 | aMethod: TRttiMethod; 105 | begin 106 | aType := context.GetType(TMyClass); 107 | 108 | Log ('Methods marked with [Simple] attribute'); 109 | for aMethod in aType.GetMethods do 110 | if HasAttribute (aMethod, SimpleAttribute) then 111 | Log (aMethod.name); 112 | 113 | Log (''); 114 | Log ('Methods marked with any attribute'); 115 | for aMethod in aType.GetMethods do 116 | if HasAttribute (aMethod, TCustomAttribute) then 117 | Log (aMethod.name); 118 | end; 119 | 120 | { TMyClass } 121 | 122 | procedure TMyClass.One; 123 | var 124 | context: TRttiContext; 125 | attributes: TArray; 126 | attrib: TCustomAttribute; 127 | begin 128 | attributes := context.GetType(ClassType).GetAttributes; 129 | for attrib in attributes do 130 | begin 131 | Form39.Log(attrib.ClassName); 132 | if attrib is ValueAttribute then 133 | Form39.Log(' -' + IntToStr (ValueAttribute(attrib).Value)); 134 | end; 135 | end; 136 | 137 | procedure TMyClass.Three; 138 | begin 139 | ShowMessage ('three'); 140 | end; 141 | 142 | procedure TMyClass.Two; 143 | begin 144 | // 145 | end; 146 | 147 | procedure TForm39.btnClassAttribsClick(Sender: TObject); 148 | begin 149 | with TMyClass.Create do 150 | begin 151 | One; 152 | end; 153 | end; 154 | 155 | procedure TForm39.Log(const strMsg: string); 156 | begin 157 | Memo1.Lines.Add (strMsg); 158 | end; 159 | 160 | end. 161 | -------------------------------------------------------------------------------- /03_Modern/07_DescriptionAttribute_VCL/DescriptionAttribute.dpr: -------------------------------------------------------------------------------- 1 | program DescriptionAttribute; 2 | 3 | uses 4 | Forms, 5 | DescriptionAttribute_MainForm in 'DescriptionAttribute_MainForm.pas' {FormDescrAttr}, 6 | DescriptionAttribute_Classes in 'DescriptionAttribute_Classes.pas'; 7 | 8 | {$R *.res} 9 | 10 | begin 11 | Application.Initialize; 12 | Application.MainFormOnTaskbar := True; 13 | Application.CreateForm(TFormDescrAttr, FormDescrAttr); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /03_Modern/07_DescriptionAttribute_VCL/DescriptionAttribute.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/03_Modern/07_DescriptionAttribute_VCL/DescriptionAttribute.res -------------------------------------------------------------------------------- /03_Modern/07_DescriptionAttribute_VCL/DescriptionAttribute_Classes.pas: -------------------------------------------------------------------------------- 1 | unit DescriptionAttribute_Classes; 2 | 3 | interface 4 | 5 | uses 6 | SysUtils; 7 | 8 | type 9 | TDescriptionAttrKind = (dakClass, dakDescription, dakId); 10 | 11 | DescriptionAttribute = class (TCustomAttribute) 12 | private 13 | fDak: TDescriptionAttrKind; 14 | public 15 | constructor Create (aDak: TDescriptionAttrKind = dakClass); 16 | property Kind: TDescriptionAttrKind read fDak; 17 | end; 18 | 19 | [Description] 20 | TPerson = class 21 | private 22 | FBirthDate: TDate; 23 | FName: string; 24 | FCountry: string; 25 | procedure SetBirthDate(const Value: TDate); 26 | procedure SetCountry(const Value: string); 27 | procedure SetName(const Value: string); 28 | public 29 | [Description (dakDescription)] 30 | function GetName: string; 31 | [Description (dakID)] 32 | function GetStringCode: Integer; 33 | published 34 | property Name: string read GetName write SetName; 35 | property BirthDate: TDate read FBirthDate write SetBirthDate; 36 | property Country: string read FCountry write SetCountry; 37 | end; 38 | 39 | [Description] 40 | TCompany = class 41 | private 42 | FName: string; 43 | FCountry: string; 44 | FID: string; 45 | procedure SetName(const Value: string); 46 | procedure SetID(const Value: string); 47 | public 48 | [Description (dakDescription)] 49 | function GetName: string; 50 | [Description (dakID)] 51 | function GetID: string; 52 | published 53 | property Name: string read GetName write SetName; 54 | property Country: string read FCountry write FCountry; 55 | property ID: string read FID write SetID; 56 | end; 57 | 58 | implementation 59 | 60 | { DescriptionAttribute } 61 | 62 | constructor DescriptionAttribute.Create(aDak: TDescriptionAttrKind); 63 | begin 64 | fDak := aDak; 65 | end; 66 | 67 | { TPerson } 68 | 69 | function TPerson.GetName: string; 70 | begin 71 | Result := fName; 72 | end; 73 | 74 | function TPerson.GetStringCode: Integer; 75 | begin 76 | inherited GethashCode; 77 | end; 78 | 79 | procedure TPerson.SetBirthDate(const Value: TDate); 80 | begin 81 | FBirthDate := Value; 82 | end; 83 | 84 | procedure TPerson.SetCountry(const Value: string); 85 | begin 86 | FCountry := Value; 87 | end; 88 | 89 | procedure TPerson.SetName(const Value: string); 90 | begin 91 | FName := Value; 92 | end; 93 | 94 | { TCompany } 95 | 96 | function TCompany.GetID: string; 97 | begin 98 | Result := fID; 99 | end; 100 | 101 | function TCompany.GetName: string; 102 | begin 103 | Result := fName; 104 | end; 105 | 106 | procedure TCompany.SetID(const Value: string); 107 | begin 108 | FID := Value; 109 | end; 110 | 111 | procedure TCompany.SetName(const Value: string); 112 | begin 113 | fName := Value; 114 | end; 115 | 116 | end. 117 | -------------------------------------------------------------------------------- /03_Modern/07_DescriptionAttribute_VCL/DescriptionAttribute_MainForm.dfm: -------------------------------------------------------------------------------- 1 | object FormDescrAttr: TFormDescrAttr 2 | Left = 0 3 | Top = 0 4 | Caption = 'DescriptionAttributes' 5 | ClientHeight = 201 6 | ClientWidth = 578 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | OnCreate = FormCreate 15 | PixelsPerInch = 96 16 | TextHeight = 13 17 | object ListView1: TListView 18 | Left = 24 19 | Top = 16 20 | Width = 537 21 | Height = 169 22 | Columns = < 23 | item 24 | Caption = 'ID' 25 | Width = 150 26 | end 27 | item 28 | AutoSize = True 29 | Caption = 'Description' 30 | end> 31 | TabOrder = 0 32 | ViewStyle = vsReport 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /03_Modern/07_DescriptionAttribute_VCL/DescriptionAttribute_MainForm.pas: -------------------------------------------------------------------------------- 1 | unit DescriptionAttribute_MainForm; 2 | 3 | interface 4 | 5 | uses 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 | Dialogs, Contnrs, ComCtrls, Generics.Collections; 8 | 9 | type 10 | TFormDescrAttr = class(TForm) 11 | ListView1: TListView; 12 | procedure FormCreate(Sender: TObject); 13 | private 14 | fObjectsList: TObjectList; 15 | public 16 | procedure UpdateList; 17 | end; 18 | 19 | var 20 | FormDescrAttr: TFormDescrAttr; 21 | 22 | implementation 23 | 24 | {$R *.dfm} 25 | 26 | uses 27 | DescriptionAttribute_Classes, RTTI; 28 | 29 | procedure TFormDescrAttr.FormCreate(Sender: TObject); 30 | var 31 | aPerson: TPerson; 32 | aCompany: TCompany; 33 | begin 34 | fObjectsList := TObjectList.Create; 35 | 36 | // add a person 37 | aPerson := TPerson.Create; 38 | aPerson.Name := 'Wiley'; 39 | aPerson.Country := 'Desert'; 40 | aPerson.BirthDate := Date - 1000; 41 | fObjectsList.Add(aPerson); 42 | 43 | // add a company 44 | aCompany := TCompany.Create; 45 | aCompany.Name := 'ACME Inc.'; 46 | aCompany.ID := IntToStr (GetTickCount); 47 | aCompany.Country := 'Worldwide'; 48 | fObjectsList.Add(aCompany); 49 | 50 | // add an unrelated object 51 | fObjectsList.Add(TStringList.Create); 52 | 53 | UpdateList; 54 | end; 55 | 56 | function TypeHasDescription (aType: TRttiType): Boolean; 57 | var 58 | attrib: TCustomAttribute; 59 | begin 60 | for attrib in aType.GetAttributes do 61 | begin 62 | if (attrib is DescriptionAttribute) then 63 | Exit(True); 64 | end; 65 | Result := False; 66 | end; 67 | 68 | procedure TFormDescrAttr.UpdateList; 69 | var 70 | anObject: TObject; 71 | context: TRttiContext; 72 | aType: TRttiType; 73 | attrib: TCustomAttribute; 74 | aMethod: TRttiMethod; 75 | strDescr, strID: string; 76 | begin 77 | for anObject in fObjectsList do 78 | begin 79 | aType := context.GetType(anObject.ClassInfo); 80 | if TypeHasDescription (aType) then 81 | begin 82 | for aMethod in aType.GetMethods do 83 | for attrib in aMethod.GetAttributes do 84 | if attrib is DescriptionAttribute then 85 | case DescriptionAttribute(attrib).Kind of 86 | dakClass: ; // ignore 87 | dakDescription: 88 | // should check if duplicate attribute 89 | strDescr := aMethod.Invoke( 90 | anObject, []).ToString; 91 | dakId: 92 | strID := aMethod.Invoke( 93 | anObject, []).ToString; 94 | end; 95 | // done looking for attributes 96 | // should check if we found anything 97 | with ListView1.Items.Add do 98 | begin 99 | Caption := strID; 100 | SubItems.Add(strDescr); 101 | end; 102 | end; 103 | end; 104 | // else ignore the object, could raise an exception 105 | end; 106 | 107 | end. 108 | -------------------------------------------------------------------------------- /03_Modern/ProjectGroup3.groupproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {D9C53617-BFD2-4873-8B29-8A895E366C88} 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | Default.Personality.12 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /04_AnonPPL/01_AnonymFirst_VCL/AnonymFirst.dpr: -------------------------------------------------------------------------------- 1 | program AnonymFirst; 2 | 3 | uses 4 | Forms, 5 | AnonymFirst_MainForm in 'AnonymFirst_MainForm.pas' {FormAnonymFirst}; 6 | 7 | {$R *.res} 8 | 9 | begin 10 | Application.Initialize; 11 | Application.MainFormOnTaskbar := True; 12 | Application.CreateForm(TFormAnonymFirst, FormAnonymFirst); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /04_AnonPPL/01_AnonymFirst_VCL/AnonymFirst.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/04_AnonPPL/01_AnonymFirst_VCL/AnonymFirst.res -------------------------------------------------------------------------------- /04_AnonPPL/01_AnonymFirst_VCL/AnonymFirst_MainForm.dfm: -------------------------------------------------------------------------------- 1 | object FormAnonymFirst: TFormAnonymFirst 2 | Left = 0 3 | Top = 0 4 | Caption = 'AnonymFirst' 5 | ClientHeight = 310 6 | ClientWidth = 554 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | PixelsPerInch = 96 15 | TextHeight = 13 16 | object btnSimpleVar: TButton 17 | Left = 8 18 | Top = 8 19 | Width = 114 20 | Height = 25 21 | Caption = 'btnSimpleVar' 22 | TabOrder = 0 23 | OnClick = btnSimpleVarClick 24 | end 25 | object Memo1: TMemo 26 | Left = 136 27 | Top = 8 28 | Width = 409 29 | Height = 273 30 | TabOrder = 1 31 | end 32 | object btnProcParam: TButton 33 | Left = 8 34 | Top = 40 35 | Width = 114 36 | Height = 25 37 | Caption = 'btnProcParam' 38 | TabOrder = 2 39 | OnClick = btnProcParamClick 40 | end 41 | object btnLocalVal: TButton 42 | Left = 8 43 | Top = 72 44 | Width = 114 45 | Height = 25 46 | Caption = 'btnLocalVal' 47 | TabOrder = 3 48 | OnClick = btnLocalValClick 49 | end 50 | object btnStore: TButton 51 | Left = 8 52 | Top = 120 53 | Width = 114 54 | Height = 25 55 | Caption = 'btnStore' 56 | TabOrder = 4 57 | OnClick = btnStoreClick 58 | end 59 | object btnCall: TButton 60 | Left = 8 61 | Top = 152 62 | Width = 114 63 | Height = 25 64 | Caption = 'btnCall' 65 | TabOrder = 5 66 | OnClick = btnCallClick 67 | end 68 | object btnNoParen: TButton 69 | Left = 8 70 | Top = 184 71 | Width = 114 72 | Height = 25 73 | Caption = 'btnNoParen' 74 | TabOrder = 6 75 | end 76 | object btReturn: TButton 77 | Left = 8 78 | Top = 248 79 | Width = 114 80 | Height = 25 81 | Caption = 'btReturn' 82 | TabOrder = 7 83 | OnClick = btReturnClick 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /04_AnonPPL/01_AnonymFirst_VCL/AnonymFirst_MainForm.pas: -------------------------------------------------------------------------------- 1 | unit AnonymFirst_MainForm; 2 | 3 | interface 4 | 5 | uses 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 | Dialogs, StdCtrls; 8 | 9 | 10 | // anonymous method type declaration 11 | type 12 | TIntProc = reference to procedure (n: Integer); 13 | 14 | // method reference type declaration (not used, only to compare syntax) 15 | type 16 | TIntMethod = procedure (n: Integer) of object; 17 | 18 | type 19 | TFormAnonymFirst = class(TForm) 20 | btnSimpleVar: TButton; 21 | Memo1: TMemo; 22 | btnProcParam: TButton; 23 | btnLocalVal: TButton; 24 | btnStore: TButton; 25 | btnCall: TButton; 26 | btnNoParen: TButton; 27 | btReturn: TButton; 28 | procedure btnSimpleVarClick(Sender: TObject); 29 | procedure btnProcParamClick(Sender: TObject); 30 | procedure btnLocalValClick(Sender: TObject); 31 | procedure btnStoreClick(Sender: TObject); 32 | procedure btnCallClick(Sender: TObject); 33 | procedure btReturnClick(Sender: TObject); 34 | private 35 | FAnonMeth: TIntProc; 36 | procedure SetAnonMeth(const Value: TIntProc); 37 | function GetShowMethod: TIntProc; 38 | public 39 | property AnonMeth: TIntProc read FAnonMeth write SetAnonMeth; 40 | end; 41 | 42 | var 43 | FormAnonymFirst: TFormAnonymFirst; 44 | 45 | implementation 46 | 47 | {$R *.dfm} 48 | 49 | procedure CallTwice (value: Integer; anIntProc: TIntProc); 50 | begin 51 | anIntProc (value); 52 | Inc (value); 53 | anIntProc (value); 54 | end; 55 | 56 | procedure TFormAnonymFirst.btnCallClick(Sender: TObject); 57 | begin 58 | if Assigned (AnonMeth) then 59 | begin 60 | AnonMeth(5); 61 | end; 62 | end; 63 | 64 | procedure TFormAnonymFirst.btnLocalValClick(Sender: TObject); 65 | var 66 | aNumber: Integer; 67 | begin 68 | aNumber := 0; 69 | CallTwice (10, 70 | procedure (n: Integer) 71 | begin 72 | Inc (aNumber, n); 73 | end); 74 | Memo1.Lines.Add (IntToStr (aNumber)); 75 | end; 76 | 77 | procedure TFormAnonymFirst.btnProcParamClick(Sender: TObject); 78 | begin 79 | CallTwice (48, 80 | procedure (n: Integer) 81 | begin 82 | Memo1.Lines.Add (IntToHex (n, 4)); 83 | end); 84 | CallTwice (100, 85 | procedure (n: Integer) 86 | begin 87 | Memo1.Lines.Add (FloatToStr(Sqrt(n))); 88 | end); 89 | end; 90 | 91 | procedure TFormAnonymFirst.btnSimpleVarClick(Sender: TObject); 92 | var 93 | anIntProc: TIntProc; 94 | begin 95 | anIntProc := procedure (n: Integer) 96 | begin 97 | Memo1.Lines.Add (IntToStr (n)); 98 | end; 99 | anIntProc (22); 100 | anIntProc (22); 101 | end; 102 | 103 | procedure TFormAnonymFirst.btnStoreClick(Sender: TObject); 104 | var 105 | aNumber: Integer; 106 | begin 107 | aNumber := 3; 108 | AnonMeth := 109 | procedure (n: Integer) 110 | begin 111 | Inc (aNumber, n); 112 | Memo1.Lines.Add (IntToStr (aNumber)); 113 | end; 114 | end; 115 | 116 | function TFormAnonymFirst.GetShowMethod: TIntProc; 117 | var 118 | x: Integer; 119 | begin 120 | x := Random (100); 121 | Memo1.Lines.Add ('New x is ' + IntToStr (x)); 122 | Result := procedure (n: Integer) 123 | begin 124 | x := x + n; 125 | Memo1.Lines.Add (IntToStr (x)); 126 | end; 127 | end; 128 | 129 | procedure TFormAnonymFirst.btReturnClick(Sender: TObject); 130 | var 131 | ip: TIntProc; 132 | begin 133 | GetShowMethod; // compiles, but probably not what you want 134 | 135 | // call using a te 136 | // ip := GetShowMethod; // E2010 Incompatible types: 'TIntProc' and 'Procedure of object' 137 | ip := GetShowMethod(); 138 | ip (3); 139 | 140 | // GetShowMethod(3); // E2034 Too many actual parameters 141 | GetShowMethod()(3); 142 | 143 | // GetShowMethod.Invoke (3), listed in the book, stopped working in recent versions of the compiler 144 | end; 145 | 146 | procedure TFormAnonymFirst.SetAnonMeth(const Value: TIntProc); 147 | begin 148 | FAnonMeth := Value; 149 | end; 150 | 151 | initialization 152 | Randomize; 153 | 154 | end. 155 | -------------------------------------------------------------------------------- /04_AnonPPL/02_AnonButton/AnonButton.dpr: -------------------------------------------------------------------------------- 1 | program AnonButton; 2 | 3 | uses 4 | System.StartUpCopy, 5 | // FMX.MobilePreview, 6 | FMX.Forms, 7 | AnonButtonForm in 'AnonButtonForm.pas' {Form1}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /04_AnonPPL/02_AnonButton/AnonButton.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/04_AnonPPL/02_AnonButton/AnonButton.res -------------------------------------------------------------------------------- /04_AnonPPL/02_AnonButton/AnonButtonForm.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 567 6 | ClientWidth = 384 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 3 11 | object Memo1: TMemo 12 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 13 | DataDetectorTypes = [] 14 | Align = Client 15 | Size.Width = 384.000000000000000000 16 | Size.Height = 435.000000000000000000 17 | Size.PlatformDefault = False 18 | TabOrder = 0 19 | Viewport.Width = 376.000000000000000000 20 | Viewport.Height = 427.000000000000000000 21 | end 22 | object btnAssign: TButton 23 | Align = Top 24 | Size.Width = 384.000000000000000000 25 | Size.Height = 44.000000000000000000 26 | Size.PlatformDefault = False 27 | TabOrder = 1 28 | Text = 'btnAssign' 29 | OnClick = btnAssignClick 30 | end 31 | object btnInvoke: TButton 32 | Align = Top 33 | Position.Y = 44.000000000000000000 34 | Size.Width = 384.000000000000000000 35 | Size.Height = 44.000000000000000000 36 | Size.PlatformDefault = False 37 | TabOrder = 3 38 | Text = 'btnInvoke' 39 | end 40 | object btnKeepRef: TButton 41 | Align = Top 42 | Position.Y = 88.000000000000000000 43 | Size.Width = 384.000000000000000000 44 | Size.Height = 44.000000000000000000 45 | Size.PlatformDefault = False 46 | TabOrder = 2 47 | Text = 'btnKeepRef' 48 | OnClick = btnKeepRefClick 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /04_AnonPPL/02_AnonButton/AnonButtonForm.pas: -------------------------------------------------------------------------------- 1 | unit AnonButtonForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Layouts, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; 9 | 10 | type 11 | TAnonNotif = reference to procedure (Sender: TObject); 12 | 13 | // interceptor class 14 | TButton = class (FMX.StdCtrls.TButton) 15 | private 16 | FAnonClick: TAnonNotif; 17 | procedure SetAnonClick(const Value: TAnonNotif); 18 | public 19 | procedure Click; override; 20 | public 21 | property AnonClick: TAnonNotif 22 | read FAnonClick write SetAnonClick; 23 | end; 24 | 25 | type 26 | TForm1 = class(TForm) 27 | Memo1: TMemo; 28 | btnAssign: TButton; 29 | btnInvoke: TButton; 30 | btnKeepRef: TButton; 31 | procedure btnAssignClick(Sender: TObject); 32 | procedure btnKeepRefClick(Sender: TObject); 33 | private 34 | { Private declarations } 35 | public 36 | procedure Show (const msg: string); 37 | end; 38 | 39 | var 40 | Form1: TForm1; 41 | 42 | implementation 43 | 44 | {$R *.fmx} 45 | 46 | procedure TButton.SetAnonClick(const Value: TAnonNotif); 47 | begin 48 | FAnonClick := Value; 49 | end; 50 | 51 | procedure TButton.Click; 52 | begin 53 | if Assigned (FAnonClick) then 54 | FAnonClick (self); 55 | inherited; 56 | end; 57 | 58 | procedure TForm1.btnAssignClick(Sender: TObject); 59 | begin 60 | btnInvoke.AnonClick := 61 | procedure (Sender: TObject) 62 | begin 63 | ShowMessage ((Sender as TButton).Text); 64 | end; 65 | end; 66 | 67 | procedure TForm1.btnKeepRefClick(Sender: TObject); 68 | var 69 | aCompRef: TComponent; 70 | begin 71 | aCompRef := Sender as TComponent; 72 | btnInvoke.AnonClick := 73 | procedure (Sender: TObject) 74 | begin 75 | ShowMessage ((Sender as TButton).Text + 76 | ' assigned by ' + aCompRef.Name); 77 | end; 78 | end; 79 | 80 | procedure TForm1.Show(const Msg: string); 81 | begin 82 | Memo1.Lines.Add(Msg); 83 | end; 84 | 85 | end. 86 | -------------------------------------------------------------------------------- /04_AnonPPL/03_ParallelFor/AndroidManifest.template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | <%uses-permission%> 11 | 20 | 22 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /04_AnonPPL/03_ParallelFor/Entitlement.TemplateOSX32.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <%appSandboxKeys%> 6 | 7 | 8 | -------------------------------------------------------------------------------- /04_AnonPPL/03_ParallelFor/ParallelForGroup.groupproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {1617E570-B01A-4743-97B7-C1F6B0589DFE} 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Default.Personality.12 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /04_AnonPPL/03_ParallelFor/ParallelForMultiForm.fmx: -------------------------------------------------------------------------------- 1 | object Form5: TForm5 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form5' 5 | ClientHeight = 480 6 | ClientWidth = 376 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object GridPanelLayout1: TGridPanelLayout 12 | Align = Top 13 | Size.Width = 376.000000000000000000 14 | Size.Height = 33.000000000000000000 15 | Size.PlatformDefault = False 16 | TabOrder = 0 17 | ColumnCollection = < 18 | item 19 | Value = 50.000000000000000000 20 | end 21 | item 22 | Value = 50.000000000000000000 23 | end> 24 | ControlCollection = < 25 | item 26 | Column = 0 27 | Control = btnForLoop 28 | Row = 0 29 | end 30 | item 31 | Column = 1 32 | Control = btnParallelFor 33 | Row = 0 34 | end> 35 | RowCollection = < 36 | item 37 | Value = 100.000000000000000000 38 | end 39 | item 40 | SizeStyle = Auto 41 | end> 42 | object btnForLoop: TButton 43 | Align = Client 44 | Size.Width = 188.000000000000000000 45 | Size.Height = 33.000000000000000000 46 | Size.PlatformDefault = False 47 | TabOrder = 0 48 | Text = 'For Loop' 49 | OnClick = btnForLoopClick 50 | end 51 | object btnParallelFor: TButton 52 | Align = Client 53 | Size.Width = 188.000000000000000000 54 | Size.Height = 33.000000000000000000 55 | Size.PlatformDefault = False 56 | TabOrder = 1 57 | Text = 'Parallel For' 58 | OnClick = btnParallelForClick 59 | end 60 | end 61 | object Memo1: TMemo 62 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 63 | DataDetectorTypes = [] 64 | Align = Client 65 | Size.Width = 376.000000000000000000 66 | Size.Height = 447.000000000000000000 67 | Size.PlatformDefault = False 68 | TabOrder = 1 69 | Viewport.Width = 372.000000000000000000 70 | Viewport.Height = 443.000000000000000000 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /04_AnonPPL/03_ParallelFor/ParallelForMultiForm.pas: -------------------------------------------------------------------------------- 1 | unit ParallelForMultiForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Memo, FMX.StdCtrls, FMX.ScrollBox, FMX.Controls.Presentation; 9 | 10 | type 11 | TForm5 = class(TForm) 12 | btnForLoop: TButton; 13 | GridPanelLayout1: TGridPanelLayout; 14 | btnParallelFor: TButton; 15 | Memo1: TMemo; 16 | procedure btnForLoopClick(Sender: TObject); 17 | procedure btnParallelForClick(Sender: TObject); 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | Form5: TForm5; 26 | 27 | implementation 28 | 29 | uses 30 | System.Threading, System.Diagnostics, System.SyncObjs; 31 | 32 | {$R *.fmx} 33 | 34 | {function local to the unit} 35 | function IsPrime (N: Integer): Boolean; 36 | var 37 | Test: Integer; 38 | begin 39 | IsPrime := True; 40 | for Test := 2 to N - 1 do 41 | if (N mod Test) = 0 then 42 | begin 43 | IsPrime := False; 44 | break; {jump out of the for loop} 45 | end; 46 | end; 47 | 48 | const 49 | Max = 50000; // 50K 50 | 51 | procedure TForm5.btnForLoopClick(Sender: TObject); 52 | var 53 | I, Tot: Integer; 54 | SW: TStopwatch; 55 | begin 56 | // counts the prime numbers below a given value 57 | Tot := 0; 58 | SW := TStopWatch.Create; 59 | SW.Start; 60 | for I := 1 to Max do 61 | begin 62 | if IsPrime (I) then 63 | Inc (Tot); 64 | // Application.ProcessMessages; 65 | end; 66 | SW.Stop; 67 | Memo1.Lines.Add (Format ( 68 | 'Plain for loop: %d - %d', [SW.ElapsedMilliseconds, Tot])); 69 | end; 70 | 71 | procedure TForm5.btnParallelForClick(Sender: TObject); 72 | var 73 | Tot: Integer; 74 | SW: TStopwatch; 75 | begin 76 | // counts the prime numbers below a given value 77 | Tot := 0; 78 | SW := TStopWatch.Create; 79 | SW.Start; 80 | TParallel.For(2, 1, Max, procedure (I: Integer) 81 | begin 82 | if IsPrime (I) then 83 | TInterlocked.Increment (Tot); 84 | end); 85 | SW.Stop; 86 | Memo1.Lines.Add (Format ( 87 | 'Plain for loop: %d - %d', [SW.ElapsedMilliseconds, Tot])); 88 | end; 89 | 90 | end. 91 | -------------------------------------------------------------------------------- /04_AnonPPL/03_ParallelFor/ParallelForVCL.dpr: -------------------------------------------------------------------------------- 1 | program ParallelForVCL; 2 | 3 | uses 4 | Forms, 5 | ParallelFor_MainForm in 'ParallelFor_MainForm.pas' {FormParallelFor}; 6 | 7 | {$R *.res} 8 | 9 | begin 10 | Application.Initialize; 11 | Application.CreateForm(TFormParallelFor, FormParallelFor); 12 | Application.Run; 13 | end. 14 | -------------------------------------------------------------------------------- /04_AnonPPL/03_ParallelFor/ParallelFor_MainForm.dfm: -------------------------------------------------------------------------------- 1 | object FormParallelFor: TFormParallelFor 2 | Left = 206 3 | Top = 147 4 | Width = 437 5 | Height = 496 6 | HorzScrollBar.Range = 44 7 | HorzScrollBar.Tracking = True 8 | VertScrollBar.Range = 89 9 | Caption = 'ParallelFor' 10 | Color = clBtnFace 11 | Font.Charset = DEFAULT_CHARSET 12 | Font.Color = clWindowText 13 | Font.Height = -11 14 | Font.Name = 'MS Sans Serif' 15 | Font.Style = [] 16 | OldCreateOrder = True 17 | PixelsPerInch = 96 18 | TextHeight = 13 19 | object btnPlainForLoop: TButton 20 | Left = 24 21 | Top = 24 22 | Width = 185 23 | Height = 25 24 | Caption = 'btnPlainForLoop' 25 | TabOrder = 0 26 | OnClick = btnPlainForLoopClick 27 | end 28 | object Memo1: TMemo 29 | Left = 24 30 | Top = 64 31 | Width = 376 32 | Height = 369 33 | TabOrder = 1 34 | end 35 | object btnParallelForLoop: TButton 36 | Left = 215 37 | Top = 24 38 | Width = 185 39 | Height = 25 40 | Caption = 'btnParallelForLoop' 41 | TabOrder = 2 42 | OnClick = btnParallelForLoopClick 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /04_AnonPPL/03_ParallelFor/ParallelFor_MainForm.pas: -------------------------------------------------------------------------------- 1 | unit ParallelFor_MainForm; 2 | 3 | interface 4 | 5 | uses 6 | SysUtils, Types, Classes, Variants, Graphics, Controls, 7 | Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Windows; 8 | 9 | type 10 | TFormParallelFor = class(TForm) 11 | btnPlainForLoop: TButton; 12 | Memo1: TMemo; 13 | btnParallelForLoop: TButton; 14 | procedure btnPlainForLoopClick(Sender: TObject); 15 | procedure btnParallelForLoopClick(Sender: TObject); 16 | private 17 | { Private declarations } 18 | public 19 | { Public declarations } 20 | end; 21 | 22 | var 23 | FormParallelFor: TFormParallelFor; 24 | 25 | implementation 26 | 27 | {$R *.dfm} 28 | 29 | uses 30 | SyncObjs, System.Threading, System.Diagnostics; 31 | 32 | {function local to the unit} 33 | function IsPrime (N: Integer): Boolean; 34 | var 35 | Test: Integer; 36 | begin 37 | IsPrime := True; 38 | for Test := 2 to N - 1 do 39 | if (N mod Test) = 0 then 40 | begin 41 | IsPrime := False; 42 | break; {jump out of the for loop} 43 | end; 44 | end; 45 | 46 | const 47 | Max = 100000; // 100K 48 | 49 | procedure TFormParallelFor.btnPlainForLoopClick(Sender: TObject); 50 | var 51 | I, Tot: Integer; 52 | Ticks: Cardinal; 53 | begin 54 | // counts the prime numbers below a given value 55 | Tot := 0; 56 | Ticks := GetTickCount; 57 | for I := 1 to Max do 58 | begin 59 | if IsPrime (I) then 60 | Inc (Tot); 61 | //Application.ProcessMessages; 62 | end; 63 | Ticks := GetTickCount - Ticks; 64 | Memo1.Lines.Add (Format ( 65 | 'Plain for: %d - %d', [Ticks, Tot])); 66 | end; 67 | 68 | procedure TFormParallelFor.btnParallelForLoopClick(Sender: TObject); 69 | var 70 | Tot: Integer; 71 | Ticks: Cardinal; 72 | begin 73 | Tot := 0; 74 | Ticks := GetTickCount; 75 | TParallel.For(1, Max, procedure (I: Int64) 76 | begin 77 | if IsPrime (I) then 78 | InterlockedIncrement (Tot); 79 | end); 80 | Ticks := GetTickCount - Ticks; 81 | Memo1.Lines.Add (Format ( 82 | 'Parallel for: %d - %d', [Ticks, Tot])); 83 | end; 84 | 85 | end. 86 | -------------------------------------------------------------------------------- /04_AnonPPL/03_ParallelFor/ParallelFor_MainForm.vlb: -------------------------------------------------------------------------------- 1 | [Memo1] 2 | Coordinates=156,10,53,51 3 | 4 | [] 5 | Coordinates=74,10,72,51 6 | 7 | [btnPlainForLoop] 8 | Coordinates=10,10,54,51 9 | 10 | -------------------------------------------------------------------------------- /04_AnonPPL/03_ParallelFor/ParallelFormMulti.dpr: -------------------------------------------------------------------------------- 1 | program ParallelFormMulti; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | ParallelForMultiForm in 'ParallelForMultiForm.pas' {Form5}; 7 | 8 | {$R *.res} 9 | 10 | begin 11 | Application.Initialize; 12 | Application.CreateForm(TForm5, Form5); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /04_AnonPPL/03_ParallelFor/ParallelFormMulti.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/04_AnonPPL/03_ParallelFor/ParallelFormMulti.res -------------------------------------------------------------------------------- /04_AnonPPL/04_AutoThreading/AutoThreading.dpr: -------------------------------------------------------------------------------- 1 | program AutoThreading; 2 | 3 | uses 4 | Forms, 5 | AutoThreading_mainForm in 'AutoThreading_mainForm.pas' {ThreadingForm}; 6 | 7 | {$R *.res} 8 | 9 | begin 10 | Application.Initialize; 11 | Application.MainFormOnTaskbar := True; 12 | Application.CreateForm(TThreadingForm, ThreadingForm); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /04_AnonPPL/04_AutoThreading/AutoThreading.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/04_AnonPPL/04_AutoThreading/AutoThreading.res -------------------------------------------------------------------------------- /04_AnonPPL/04_AutoThreading/AutoThreading_Icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/04_AnonPPL/04_AutoThreading/AutoThreading_Icon.ico -------------------------------------------------------------------------------- /04_AnonPPL/04_AutoThreading/AutoThreading_mainForm.dfm: -------------------------------------------------------------------------------- 1 | object ThreadingForm: TThreadingForm 2 | Left = 0 3 | Top = 0 4 | Caption = 'AutoThreading' 5 | ClientHeight = 312 6 | ClientWidth = 581 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | PixelsPerInch = 96 15 | TextHeight = 13 16 | object btnAutoThread: TButton 17 | Left = 48 18 | Top = 56 19 | Width = 161 20 | Height = 25 21 | Caption = 'Automatic Thread' 22 | TabOrder = 0 23 | OnClick = btnAutoThreadClick 24 | end 25 | object Button2: TButton 26 | Left = 48 27 | Top = 184 28 | Width = 161 29 | Height = 25 30 | Caption = 'Spin Demo' 31 | TabOrder = 1 32 | OnClick = Button2Click 33 | end 34 | object btnPlain: TButton 35 | Left = 48 36 | Top = 25 37 | Width = 161 38 | Height = 25 39 | Caption = 'Plain Code' 40 | TabOrder = 2 41 | OnClick = btnPlainClick 42 | end 43 | object btnBlockingHttp: TButton 44 | Left = 240 45 | Top = 25 46 | Width = 161 47 | Height = 25 48 | Caption = 'Blocking Http' 49 | TabOrder = 3 50 | OnClick = btnBlockingHttpClick 51 | end 52 | object btnThreadedHttp: TButton 53 | Left = 240 54 | Top = 56 55 | Width = 161 56 | Height = 25 57 | Caption = 'Threaded Http' 58 | TabOrder = 4 59 | OnClick = btnThreadedHttpClick 60 | end 61 | object Memo1: TMemo 62 | Left = 240 63 | Top = 96 64 | Width = 313 65 | Height = 193 66 | TabOrder = 5 67 | end 68 | object IdHTTP1: TIdHTTP 69 | AllowCookies = True 70 | ProxyParams.BasicAuthentication = False 71 | ProxyParams.ProxyPort = 0 72 | Request.ContentLength = -1 73 | Request.ContentRangeEnd = -1 74 | Request.ContentRangeStart = -1 75 | Request.ContentRangeInstanceLength = -1 76 | Request.Accept = 'text/html, */*' 77 | Request.BasicAuthentication = False 78 | Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)' 79 | Request.Ranges.Units = 'bytes' 80 | Request.Ranges = <> 81 | HTTPOptions = [hoForceEncodeParams] 82 | Left = 464 83 | Top = 32 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /04_AnonPPL/04_AutoThreading/AutoThreading_mainForm.pas: -------------------------------------------------------------------------------- 1 | unit AutoThreading_mainForm; 2 | 3 | interface 4 | 5 | uses 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 | Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, 8 | IdHTTP; 9 | 10 | type 11 | TThreadingForm = class(TForm) 12 | btnAutoThread: TButton; 13 | Button2: TButton; 14 | btnPlain: TButton; 15 | btnBlockingHttp: TButton; 16 | btnThreadedHttp: TButton; 17 | Memo1: TMemo; 18 | IdHTTP1: TIdHTTP; 19 | procedure btnAutoThreadClick(Sender: TObject); 20 | procedure Button2Click(Sender: TObject); 21 | procedure btnPlainClick(Sender: TObject); 22 | procedure btnBlockingHttpClick(Sender: TObject); 23 | procedure btnThreadedHttpClick(Sender: TObject); 24 | private 25 | { Private declarations } 26 | public 27 | { Public declarations } 28 | end; 29 | 30 | var 31 | ThreadingForm: TThreadingForm; 32 | 33 | implementation 34 | 35 | {$R *.dfm} 36 | 37 | uses 38 | Math, SyncObjs; 39 | 40 | const 41 | mil20 = 20000000; // 20 million (change it to slow down code) 42 | 43 | procedure TThreadingForm.btnAutoThreadClick(Sender: TObject); 44 | begin 45 | (Sender as TButton).Caption := 'Computing'; 46 | TThread.CreateAnonymousThread( 47 | procedure() 48 | var 49 | X: Extended; 50 | I: Integer; 51 | begin 52 | X := 100; 53 | for I := 0 to mil20 do 54 | x := Sqrt (X) * Sqrt (X); 55 | TThread.Synchronize (TThread.CurrentThread, 56 | procedure 57 | begin 58 | (Sender as TButton).Caption := FloatToStr (X); 59 | end); 60 | end).Start; 61 | end; 62 | 63 | procedure TThreadingForm.btnBlockingHttpClick(Sender: TObject); 64 | var 65 | strHtml: string; 66 | begin 67 | strHtml := IdHttp1.Get('http://www.marcocantu.com'); 68 | memo1.Lines.Add(Copy (strHtml, 1, 200)); 69 | end; 70 | 71 | procedure TThreadingForm.btnPlainClick(Sender: TObject); 72 | var 73 | X: Extended; 74 | I: Integer; 75 | begin 76 | (Sender as TButton).Caption := 'Computing'; 77 | X := 100; 78 | for I := 0 to mil20 do 79 | x := Sqrt (X) * Sqrt (X); 80 | (Sender as TButton).Caption := FloatToStr (X); 81 | end; 82 | 83 | procedure TThreadingForm.btnThreadedHttpClick(Sender: TObject); 84 | begin 85 | TThread.CreateAnonymousThread( 86 | procedure () 87 | var 88 | strHtml: string; 89 | begin 90 | strHtml := IdHttp1.Get('http://www.marcocantu.com'); 91 | TThread.Synchronize(TThread.CurrentThread, 92 | procedure () 93 | begin 94 | memo1.Lines.Add(Copy (strHtml, 1, 200)); 95 | end); 96 | end).Start; 97 | end; 98 | 99 | procedure TThreadingForm.Button2Click(Sender: TObject); 100 | var 101 | X: Extended; 102 | begin 103 | //////////// NOT A GOOD EXAMPLE OF A SPIN LOCK ////// 104 | 105 | (Sender as TButton).Caption := 'Computing'; 106 | X := 0; 107 | TThread.CreateAnonymousThread( 108 | procedure() 109 | var 110 | I: Integer; 111 | x1: Extended; 112 | begin 113 | X1 := 100; 114 | for I := 0 to mil20 do 115 | x1 := Sqrt (X1) * Sqrt (X1); 116 | x := x1; 117 | end).Start; 118 | 119 | // wait! 120 | TSpinWait.SpinUntil( 121 | function: Boolean 122 | begin 123 | Application.ProcessMessages; 124 | Result := (x <> 0); 125 | end 126 | ); 127 | 128 | (Sender as TButton).Caption := FloatToStr (X); 129 | end; 130 | 131 | end. 132 | -------------------------------------------------------------------------------- /04_AnonPPL/05_ParallelTasksAndFutures/ParallelForm.dfm: -------------------------------------------------------------------------------- 1 | object FormThreading: TFormThreading 2 | Left = 0 3 | Top = 0 4 | Caption = 'System.Threading' 5 | ClientHeight = 305 6 | ClientWidth = 586 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | PixelsPerInch = 96 15 | TextHeight = 13 16 | object Button1: TButton 17 | Left = 32 18 | Top = 24 19 | Width = 129 20 | Height = 25 21 | Caption = 'Delayed Message' 22 | TabOrder = 0 23 | OnClick = Button1Click 24 | end 25 | object Button2: TButton 26 | Left = 32 27 | Top = 64 28 | Width = 129 29 | Height = 25 30 | Caption = 'Wait for all' 31 | TabOrder = 1 32 | OnClick = Button2Click 33 | end 34 | object Button3: TButton 35 | Left = 224 36 | Top = 24 37 | Width = 129 38 | Height = 25 39 | Caption = 'Future' 40 | TabOrder = 2 41 | OnClick = Button3Click 42 | end 43 | object Memo1: TMemo 44 | Left = 224 45 | Top = 66 46 | Width = 265 47 | Height = 159 48 | TabOrder = 3 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /04_AnonPPL/05_ParallelTasksAndFutures/ParallelForm.pas: -------------------------------------------------------------------------------- 1 | unit ParallelForm; 2 | 3 | interface 4 | 5 | uses 6 | Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 7 | Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; 8 | 9 | type 10 | TFormThreading = class(TForm) 11 | Button1: TButton; 12 | Button2: TButton; 13 | Button3: TButton; 14 | Memo1: TMemo; 15 | procedure Button1Click(Sender: TObject); 16 | procedure Button2Click(Sender: TObject); 17 | procedure Button3Click(Sender: TObject); 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | FormThreading: TFormThreading; 26 | 27 | implementation 28 | 29 | {$R *.dfm} 30 | 31 | uses 32 | System.Threading, System.SyncObjs, System.RTTI; 33 | 34 | procedure TFormThreading.Button1Click(Sender: TObject); 35 | var 36 | aTask: ITask; 37 | begin 38 | // not a thread safe snippet 39 | aTask := TTask.Create (procedure () 40 | begin 41 | sleep (3000); // 3 seconds 42 | ShowMessage ('Hello'); 43 | end); 44 | aTask.Start; 45 | end; 46 | 47 | procedure TFormThreading.Button2Click(Sender: TObject); 48 | var 49 | tasks: array of ITask; 50 | value: Integer; 51 | begin 52 | Setlength (tasks ,2); 53 | value := 0; 54 | 55 | tasks[0] := TTask.Create (procedure () 56 | begin 57 | sleep (3000); // 3 seconds 58 | TInterlocked.Add (value, 3000); 59 | end); 60 | tasks[0].Start; 61 | 62 | tasks[1] := TTask.Create (procedure () 63 | begin 64 | sleep (5000); // 5 seconds 65 | TInterlocked.Add (value, 5000); 66 | end); 67 | tasks[1].Start; 68 | 69 | TTask.WaitForAll(tasks); 70 | ShowMessage ('All done: ' + value.ToString); 71 | end; 72 | 73 | function ComputeSomething: Integer; 74 | var 75 | I: Integer; 76 | begin 77 | Result := 0; 78 | for I := 0 to 10000 do 79 | Result := Result + Round(Sqrt(I)); 80 | end; 81 | 82 | procedure TFormThreading.Button3Click(Sender: TObject); 83 | var 84 | OneValue: IFuture ; 85 | OtherValue: Integer; 86 | Total: Integer; 87 | begin 88 | OneValue := TTask.Future(function: Integer 89 | begin 90 | Result := ComputeSomething; 91 | end); 92 | Memo1.Lines.Add(TRttiEnumerationType. 93 | GetName(OneValue.Status)); 94 | 95 | OtherValue := ComputeSomething; 96 | Memo1.Lines.Add(TRttiEnumerationType. 97 | GetName(OneValue.Status)); 98 | 99 | Total := OtherValue + OneValue.Value; 100 | Memo1.Lines.Add(TRttiEnumerationType. 101 | GetName(OneValue.Status)); 102 | 103 | // result 104 | Memo1.Lines.Add(Total.ToString); 105 | end; 106 | 107 | end. 108 | -------------------------------------------------------------------------------- /04_AnonPPL/05_ParallelTasksAndFutures/ParallelTaskAndFutures.dpr: -------------------------------------------------------------------------------- 1 | program ParallelTaskAndFutures; 2 | 3 | uses 4 | Vcl.Forms, 5 | ParallelForm in 'ParallelForm.pas' {FormThreading}; 6 | 7 | {$R *.res} 8 | 9 | begin 10 | Application.Initialize; 11 | Application.MainFormOnTaskbar := True; 12 | Application.CreateForm(TFormThreading, FormThreading); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /04_AnonPPL/05_ParallelTasksAndFutures/ParallelTaskAndFutures.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcocantu/2016DelphiLanguageBootCamp/1e4648ac6f4a6334b86ec6ed679108e0adfda0df/04_AnonPPL/05_ParallelTasksAndFutures/ParallelTaskAndFutures.res -------------------------------------------------------------------------------- /04_AnonPPL/ProjectGroup4.groupproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {3A189207-AC69-41F9-A280-C3AB4C3AA4E9} 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Default.Personality.12 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 2016DelphiLanguageBootCamp 2 | 3 | 2016 Delphi BootCamp Delphi Language Demos 4 | 5 | --------------------------------------------------------------------------------