Driving Behavioral Change for Information Management through Data-Driven Gree...
Intro to Event-driven Programming and Forms with Delphi L04 - Controls P2
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.
3. 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
4. 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”.
5. 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.
7. 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);
8. 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
’;
’;
’;
’;
’;
9. 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;
12. 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);
15. 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
25. Shape Prop.
• Most used for illustrating “Graphics”.
• Properties:
–
–
–
–
–
–
Shape: rectangle, circle .
Brush: Color
Pen
Width, Height
Visible, Enabled
Top, Left
26. 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.
29. 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;
30. Debugging
• Form our Menu > Run > Step Over
• Form our Menu > Run > Trace into
– Step Over : F8
– Trace into : F7
35. 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;
36. 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
37. 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
41. 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
44. 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
45. 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;
48. 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.
49. 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”