delphi l04 controls p2
TRANSCRIPT
![Page 1: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/1.jpg)
Mohammad Shakermohammadshakergtr.wordpress.com
Intro to Event-driven Programming and Forms with Delphi@ZGTRShaker
2010, 2011, 2012
Intro to Event-driven Programming and Forms with Delphi
L04 – Controls P2
![Page 2: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/2.jpg)
![Page 3: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/3.jpg)
Memo
• It’s a standard Windows multiline “edit” control.• That’s it :D• Difference to “Edit”:
– Memo allow the user to enter more than one line of text.
• necessary for “input” or “output” lengthy information.• The most used “component” to deal with “file”s
![Page 4: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/4.jpg)
Memo Prop.
• Lines (String):– Manipulate text in “Memo” control on a “line-by-line” basis.
(Manipulate individual lines of text)– Counting lines in the text.– Adding new lines.– Deleting lines.– Replacing lines with new text “String”.
![Page 5: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/5.jpg)
Memo Prop.
• ScrollBars:– None, Horizontal, Vertical, Both
• Text:– Dealing with all text at once
• MaxLength:– “Get” or “Set” maximum numbers of characters that a “Memo” can
contain.
• Count:– Numbers of current used lines.
![Page 6: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/6.jpg)
Memo functions
– Memo1.Lines.add(//String);– Memo1.Lines[i]:= //String;– Memo1.Lines.Clear;
![Page 7: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/7.jpg)
Memo functions
• Let’s test the following:– Memo1.Lines.IndexOf(Const s:string): integer;– Memo1.Lines.Insert(Index:integer, Const s:string);– Memo1.Lines.Delete(Index:integer);– Memo1.Lines.AddStrings(Strings:TStrings);
![Page 8: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/8.jpg)
Memo functions
// add to last position in memo
Memo1.Lines.add(‘heeeeeheeeeeeeI am adding to Memo ’);
// add OR modify to specific position (line) in the memo
Memo1.Lines[0]:=‘heeeeeheeeeeeeI am adding to Memo ’;
//Initializing
for I:= 0 to 4 do
Memo1.lines.add('');
//filing memo with its values
Memo1.Lines[0]:=‘heeeeeheeeeeeeI am adding to Memo ’;
Memo1.Lines[1]:=‘heeeeeheeeeeeeI am adding to Memo ’;
Memo1.Lines[2]:=‘heeeeeheeeeeeeI am adding to Memo ’;
Memo1.Lines[3]:=‘heeeeeheeeeeeeI am adding to Memo ’;
Memo1.Lines[4]:=‘heeeeeheeeeeeeI am adding to Memo ’;
When Multi lines,
InitializeFIRST
![Page 9: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/9.jpg)
Memo functions//counting number of character in memox:=Memo1.Lines.Count;
//printing integer variables into memoMemo1.lines.add(inttostr(x));
//clearing all memoMemo1.Lines.Clear;
![Page 10: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/10.jpg)
![Page 11: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/11.jpg)
ExerciseMemo Notepad
![Page 12: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/12.jpg)
Notepad MeMo
• Additional functions for “Notepad”.– Load all info form a “Specific file” to “Memo”:
– Save all info from “Memo” to a “Specific file”:Memo1.lines.LoadFromFile(Const FileName:String);
Memo1.lines.SaveToFile(Const FileName:String);
![Page 13: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/13.jpg)
StringGrid
![Page 14: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/14.jpg)
StringGrid
• “StringGrid” Contains “String”s
![Page 15: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/15.jpg)
StringGrid Prop.
• ScrollBars:– None, Horizontal, Vertical, Both
• Fixed Row\Col:– FixesCol: number of “fixed Column”s. – FixesRows: number of “fixed Row”s.
• Indexes:– ColCount: number of “column”s.– RowCount: number of “Row”s.
• Cells[i,j]: // Run Time– returns the “String” in index [i,j]
![Page 16: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/16.jpg)
StringGrid Prop.
• Option:– all “Boolean”s
• GoRowSizing, GoColSizing, default “false”.• GoRowMoving, GoColMoving, default “false”.• Most Imprtant: GoEditing “true”, default “false”. (INPUT)
![Page 17: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/17.jpg)
StringGrid
• Output– Cells[i,j]
• Input:– GoEditing “True”.
![Page 18: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/18.jpg)
MainMenu
![Page 19: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/19.jpg)
MainMenu
• U gonna like it, believe me:D• Designing Time:
![Page 20: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/20.jpg)
MainMenu
• Executing Time:
![Page 21: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/21.jpg)
MainMenu Prop.
• Items: nice & easy • That’s it, Test it live!
![Page 22: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/22.jpg)
Image
![Page 23: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/23.jpg)
Image
• Properties:– Picture – Stretch– Autosize– Width, Height– Visible, Enabled– Top, Left
![Page 24: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/24.jpg)
Shape
![Page 25: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/25.jpg)
Shape Prop.
• Most used for illustrating “Graphics”.• Properties:
– Shape: rectangle, circle .– Brush: Color– Pen– Width, Height– Visible, Enabled – Top, Left
![Page 26: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/26.jpg)
Shape most used Events
• Most Important – Create: can be used to “Auto-Create” shapes in “Runtime” using
“Pointer”s– Destroy: can be used to “Auto-Destroy” shapes at “Runtime” using
“Pointer”s– Hide – Refresh– Repaint
• “Pen, Brush, Enabledetc” properties can all be changed at “Runtime” AS USUAL.
![Page 27: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/27.jpg)
Panel
• BevelIn, BevelOut• Cutting & pasting problem• Test it
![Page 28: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/28.jpg)
Parent Property
![Page 29: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/29.jpg)
procedure TForm1.Button2Click(Sender: TObject);
begin
Button2.Parent:= Panel2;
end;
Parent Property
• Every component has sth called “Parent” – like a “Button” in a “Panel”
• So, the “Panel” is the “Parent” of the “Button”
– like a “Button” in a “Form”• So, the “Form” is the “Parent” of the “Button”
• Some Controls have no “Parent”– Form’s parent It’s “NIL”
![Page 30: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/30.jpg)
Debugging
• Form our Menu > Run > Step Over• Form our Menu > Run > Trace into
– Step Over : F8– Trace into : F7
![Page 31: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/31.jpg)
![Page 32: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/32.jpg)
What’s for today?
• Timer• Sleep• TrackBar• ProgressBar• StatusBar
![Page 33: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/33.jpg)
Timer
![Page 34: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/34.jpg)
Timer
• Properties:– Enabled : default “true”.– Interval : 1 “second” = 1000 “milli-seconds”
• Events:– OnTimer
![Page 35: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/35.jpg)
Timer
• In design time “Enabled” Prop. is: “false”.• At Runtime:
procedure TForm11.Button1Click(Sender: TObject);
Begin
Timer1.Enabled:=True;
end;
procedure TForm11.Timer1Timer(Sender: TObject);
Begin
if (strtoint(Label1.Caption)> 0) then
Label1.Caption:=inttostr(strtoint(label1.Caption)-1);
end;
![Page 36: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/36.jpg)
Sleep - Refresh
• Sleep: “Stall” s the program.
• Refresh:– To solve the “Sleep” problem, we use the “Refresh” method.– Most used for:
Form1.Refresh;
// Here the form will be refreshed
Shape1.Refresh;
// Here the shape will be refreshed
Sleep(100);
// here the program executing will be stopped for
// 0.1 sec
![Page 37: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/37.jpg)
Sleep - Refresh
• Test it live as this example:– We’ll do a simulation on one shape like Hanoi towers– Let’s have a shape “Rectangle”– Now, we want to move it upward
• WE NEED TO SEE THE MOVEMENT
![Page 38: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/38.jpg)
Time Machine :PWe can control time with: “Timer” or “Sleep”
![Page 39: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/39.jpg)
Time Machine :PTest it live!
![Page 40: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/40.jpg)
TrackBar
![Page 41: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/41.jpg)
TrackBar
• Properties:– Max : Maximum value (100).– Min : Minimum value (0).– Position: Where the “Slider” stands (1).– Orientation:
• “Vertical” or “Horizontal”
– SliderVisible:• “Boolean” for showing\hiding the “Slider”.
• Events:– Most important: OnChange
![Page 42: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/42.jpg)
TrackBar
procedure TForm11.TrackBar1Change(Sender: TObject);
Begin
Label1.caption:=inttostr(TrackBar1.Position);
end;
![Page 43: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/43.jpg)
ProgressBar
![Page 44: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/44.jpg)
ProgressBar
• Properties:– Max : Maximum value (100).– Min : Minimum value (0).– Position :
• How much “filled” the ProgressBar is (0).• This is showed just in “Run Time”.
– Orientation:• “Vertical” or “Horizontal”• if changed:
– you have to resize your “ProgressBar”, this’s a crazy thing:D
– Step (integer):• Determines how much the “one” step will be
![Page 45: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/45.jpg)
ProgressBar Example
procedure TForm1.Timer1Timer(Sender: TObject);
begin
ProgressBar1.Position:= ProgressBar1.Position + 1;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
ProgressBar1.StepIt;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
ProgressBar1.StepBy(50);
end;
![Page 46: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/46.jpg)
StatusBar
![Page 47: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/47.jpg)
StatusBar
• The one that at the bottom to indicate the form’s “status”.
![Page 48: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/48.jpg)
StatusBar Prop.
• SimplePanel:– Boolean: enables the “StatusBar” when “true”, default false.– Show the “text” when “true”.
• SimpleText: – String: The “StatusBar” text.
• Visible, Enabled, Fontetc. as usual.
![Page 49: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/49.jpg)
StatusBar notes
• Note:– We can change the “SimpleText” in runtime by writing the proper code
that match the form’s STATUS.– A “Written SimpleText” without “SimplePanel” is true will not show
anything. This’s like “Hint” & “ShowHint”
![Page 50: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/50.jpg)
StatusBar Example
procedure TForm1.Button1Click(Sender: TObject);
begin
form2.show();
StatusBar1.SimpleText:='Form2 is running';
end;
Uses unit2;
![Page 51: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/51.jpg)
StatusBar Example
Before clicking “Button1” After clicking “Button1”
![Page 52: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/52.jpg)
Timer – Shape Example
![Page 53: Delphi L04 Controls P2](https://reader036.vdocuments.net/reader036/viewer/2022081512/5553b492b4c905d9448b4c93/html5/thumbnails/53.jpg)
See you!