Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Intro to Event-driven Programming
and Forms with Delphi
L04 – Controls P2

Mohammad Shaker
mohammadshakergtr.wordpress.com...
Memo
• It’s a standard Windows multiline “edit” control.
• That’s it :D
• Difference to “Edit”:
– Memo allow the user to e...
Memo Prop.
• Lines (String):
– Manipulate text in “Memo” control on a “line-by-line” basis.
(Manipulate individual lines o...
Memo Prop.
• ScrollBars:
– None, Horizontal, Vertical, Both

• Text:
– Dealing with all text at once

• MaxLength:
– “Get”...
Memo functions
– Memo1.Lines.add(//String);
– Memo1.Lines[i]:= //String;
– Memo1.Lines.Clear;
Memo functions
• Let’s test the following:
–
–
–
–

Memo1.Lines.IndexOf(Const s:string): integer;
Memo1.Lines.Insert(Index...
Memo functions
// add to last position in memo
Memo1.Lines.add(‘heeeeeheeeeeeeI am adding to Memo ’);
// add OR modify to ...
Memo functions
//counting number of character in memo
x:=Memo1.Lines.Count;
//printing integer variables into memo
Memo1.l...
Exercise
Memo Notepad
Notepad MeMo
• Additional functions for “Notepad”.
– Load all info form a “Specific file” to “Memo”:

Memo1.lines.LoadFrom...
StringGrid
StringGrid
• “StringGrid” Contains “String”s
StringGrid Prop.
• ScrollBars:
– None, Horizontal, Vertical, Both

• Fixed RowCol:
– FixesCol: number of “fixed Column”s.
...
StringGrid Prop.
• Option:
– all “Boolean”s
• GoRowSizing, GoColSizing, default “false”.
• GoRowMoving, GoColMoving, defau...
StringGrid
• Output
– Cells[i,j]

• Input:
– GoEditing “True”.
MainMenu
MainMenu
• U gonna like it, believe me:D
• Designing Time:
MainMenu
• Executing Time:
MainMenu Prop.
• Items: nice & easy
• That’s it, Test it live!
Image
Image
• Properties:
–
–
–
–
–
–

Picture
Stretch
Autosize
Width, Height
Visible, Enabled
Top, Left
Shape
Shape Prop.
• Most used for illustrating “Graphics”.
• Properties:
–
–
–
–
–
–

Shape: rectangle, circle .
Brush: Color
Pe...
Shape most used Events
• Most Important
– Create: can be used to “Auto-Create” shapes in “Runtime” using
“Pointer”s
– Dest...
Panel
• BevelIn, BevelOut
• Cutting & pasting problem
• Test it
Parent Property
Parent Property
• Every component has sth called “Parent”
– like a “Button” in a “Panel”
• So, the “Panel” is the “Parent”...
Debugging
• Form our Menu > Run > Step Over
• Form our Menu > Run > Trace into
– Step Over : F8
– Trace into : F7
What’s for today?
•
•
•
•
•

Timer
Sleep
TrackBar
ProgressBar
StatusBar
Timer
Timer
• Properties:
– Enabled : default “true”.
– Interval : 1 “second” = 1000 “milli-seconds”

• Events:
– OnTimer
Timer
• In design time “Enabled” Prop. is: “false”.
• At Runtime:
procedure TForm11.Button1Click(Sender: TObject);
Begin
T...
Sleep - Refresh
• Sleep: “Stall” s the program.
Sleep(100);
// here the program executing will be stopped for
// 0.1 sec

...
Sleep - Refresh
• Test it live as this example:
– We’ll do a simulation on one shape like Hanoi towers
– Let’s have a shap...
Time Machine :P
We can control time with: “Timer” or “Sleep”
Time Machine :P
Test it live!
TrackBar
TrackBar
• Properties:
–
–
–
–

Max
: Maximum value (100).
Min
: Minimum value (0).
Position: Where the “Slider” stands (1...
TrackBar

procedure TForm11.TrackBar1Change(Sender: TObject);
Begin
Label1.caption:=inttostr(TrackBar1.Position);
end;
ProgressBar
ProgressBar
• Properties:
– Max
– Min
– Position

: Maximum value (100).
: Minimum value (0).
:

• How much “filled” the P...
ProgressBar Example
procedure TForm1.Timer1Timer(Sender: TObject);
begin
ProgressBar1.Position:= ProgressBar1.Position + 1...
StatusBar
StatusBar
• The one that at the bottom to indicate the form’s “status”.
StatusBar Prop.
• SimplePanel:
– Boolean: enables the “StatusBar” when “true”, default false.
– Show the “text” when “true...
StatusBar notes
• Note:
– We can change the “SimpleText” in runtime by writing the proper code
that match the form’s STATU...
StatusBar Example
Uses unit2;
procedure TForm1.Button1Click(Sender: TObject);
begin
form2.show();
StatusBar1.SimpleText:='...
StatusBar Example
Before clicking “Button1”

After clicking “Button1”
Timer – Shape Example
See you!
Delphi L04 Controls P2
Delphi L04 Controls P2
Delphi L04 Controls P2
Upcoming SlideShare
Loading in …5
×

Delphi L04 Controls P2

1,035 views

Published on

Published in: Technology, Health & Medicine
  • Be the first to comment

Delphi L04 Controls P2

  1. 1. Intro to Event-driven Programming and Forms with Delphi L04 – Controls P2 Mohammad Shaker mohammadshakergtr.wordpress.com Intro to Event-driven Programming and Forms with Delphi @ZGTRShaker 2010, 2011, 2012
  2. 2. 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
  3. 3. 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”.
  4. 4. 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.
  5. 5. Memo functions – Memo1.Lines.add(//String); – Memo1.Lines[i]:= //String; – Memo1.Lines.Clear;
  6. 6. 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);
  7. 7. 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 Memo1.Lines[1]:=‘heeeeeheeeeeeeI Memo1.Lines[2]:=‘heeeeeheeeeeeeI Memo1.Lines[3]:=‘heeeeeheeeeeeeI Memo1.Lines[4]:=‘heeeeeheeeeeeeI When Multi lines, Initialize FIRST am am am am am adding adding adding adding adding to to to to to Memo Memo Memo Memo Memo ’; ’; ’; ’; ’;
  8. 8. Memo functions //counting number of character in memo x:=Memo1.Lines.Count; //printing integer variables into memo Memo1.lines.add(inttostr(x)); //clearing all memo Memo1.Lines.Clear;
  9. 9. Exercise Memo Notepad
  10. 10. Notepad MeMo • Additional functions for “Notepad”. – Load all info form a “Specific file” to “Memo”: Memo1.lines.LoadFromFile(Const FileName:String); – Save all info from “Memo” to a “Specific file”: Memo1.lines.SaveToFile(Const FileName:String);
  11. 11. StringGrid
  12. 12. StringGrid • “StringGrid” Contains “String”s
  13. 13. StringGrid Prop. • ScrollBars: – None, Horizontal, Vertical, Both • Fixed RowCol: – 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]: – returns the “String” in index [i,j] // Run Time
  14. 14. StringGrid Prop. • Option: – all “Boolean”s • GoRowSizing, GoColSizing, default “false”. • GoRowMoving, GoColMoving, default “false”. • Most Imprtant: GoEditing “true”, default “false”. (INPUT)
  15. 15. StringGrid • Output – Cells[i,j] • Input: – GoEditing “True”.
  16. 16. MainMenu
  17. 17. MainMenu • U gonna like it, believe me:D • Designing Time:
  18. 18. MainMenu • Executing Time:
  19. 19. MainMenu Prop. • Items: nice & easy • That’s it, Test it live!
  20. 20. Image
  21. 21. Image • Properties: – – – – – – Picture Stretch Autosize Width, Height Visible, Enabled Top, Left
  22. 22. Shape
  23. 23. Shape Prop. • Most used for illustrating “Graphics”. • Properties: – – – – – – Shape: rectangle, circle . Brush: Color Pen Width, Height Visible, Enabled Top, Left
  24. 24. 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.
  25. 25. Panel • BevelIn, BevelOut • Cutting & pasting problem • Test it
  26. 26. Parent Property
  27. 27. 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” procedure TForm1.Button2Click(Sender: TObject); begin Button2.Parent:= Panel2; end;
  28. 28. Debugging • Form our Menu > Run > Step Over • Form our Menu > Run > Trace into – Step Over : F8 – Trace into : F7
  29. 29. What’s for today? • • • • • Timer Sleep TrackBar ProgressBar StatusBar
  30. 30. Timer
  31. 31. Timer • Properties: – Enabled : default “true”. – Interval : 1 “second” = 1000 “milli-seconds” • Events: – OnTimer
  32. 32. 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;
  33. 33. Sleep - Refresh • Sleep: “Stall” s the program. Sleep(100); // here the program executing will be stopped for // 0.1 sec • 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
  34. 34. 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
  35. 35. Time Machine :P We can control time with: “Timer” or “Sleep”
  36. 36. Time Machine :P Test it live!
  37. 37. TrackBar
  38. 38. TrackBar • Properties: – – – – Max : Maximum value (100). Min : Minimum value (0). Position: Where the “Slider” stands (1). Orientation: • “Vertical” or “Horizontal” – SliderVisible: • “Boolean” for showinghiding the “Slider”. • Events: – Most important: OnChange
  39. 39. TrackBar procedure TForm11.TrackBar1Change(Sender: TObject); Begin Label1.caption:=inttostr(TrackBar1.Position); end;
  40. 40. ProgressBar
  41. 41. ProgressBar • Properties: – Max – Min – Position : Maximum value (100). : Minimum value (0). : • 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
  42. 42. 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;
  43. 43. StatusBar
  44. 44. StatusBar • The one that at the bottom to indicate the form’s “status”.
  45. 45. 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.
  46. 46. 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”
  47. 47. StatusBar Example Uses unit2; procedure TForm1.Button1Click(Sender: TObject); begin form2.show(); StatusBar1.SimpleText:='Form2 is running'; end;
  48. 48. StatusBar Example Before clicking “Button1” After clicking “Button1”
  49. 49. Timer – Shape Example
  50. 50. See you!

×