SlideShare a Scribd company logo
1 of 31
Download to read offline
Intro to Event-driven Programming
and Forms with Delphi
L07 - Creating Controls at Runtime
Part 1

Mohammad Shaker
mohammadshakergtr.wordpress.com
Intro to Event-driven Programming and Forms with Delphi
@ZGTRShaker
2010, 2011, 2012
Creating Controls at Runtime
• Let’s have the following form design
Creating Controls at Runtime
•We declare the “control” like any other variable
var i: Integer;
var TempShape:TShape;

procedure TForm2.Button1Click(Sender: TObject);
begin
// Now we initialize the shape to use it as a NORMAL
// one
TempShape:= TShape.Create(self);
End;
Creating Controls at Runtime
• Compiler Error
– Tshape is undeclared type

• So don’t forget to add ExtCtrls.
uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms, Dialogs, StdCtrls,
ExtCtrls;
Creating Controls at Runtime
•Compile and Run but no shape outputted after writing the

following code.
– What’s messing?
Var TempShape:Tshape;
procedure TForm2.Button1Click(Sender: TObject);
begin
// Now we initialize the shape to use it as a NORMAL
// one
TempShape:= Tshape.Create(self);
End;
Creating Controls at Runtime
procedure TForm2.Button1Click(Sender: TObject);
begin
TempShape:= Tshape.Create(self);
TempShape.Parent:= Panel1;
end;
Creating Controls at Runtime
procedure TForm2.Button1Click(Sender: TObject);
begin
TempShape:= Tshape.Create(self);
TempShape.Parent:= Panel1;
TempShape.Shape:= stEllipse;
TempShape.Height:= 100;
TempShape.Width:= 50;
TempShape.Left:= 100;
TempShape.Top:= 50;
TempShape.Brush.Color:= 255;
end;
Creating Controls at Runtime
Creating Controls at Runtime
• Let’s have the following form design
Creating Controls at Runtime
procedure TForm2.Button1Click(Sender: TObject);
var i: integer;
ShapeArr: Array [1..5] of TShape;
begin
for i:= 1 to 5 do
Begin
ShapeArr[i]:= TShape.Create(self);
ShapeArr[i].Parent:= Panel1;
ShapeArr[i].Brush.Color:= i*100;
ShapeArr[i].Left:= 100;
ShapeArr[i].Top:= i*40;
End;
end;
Creating Controls at Runtime
Creating Controls at Runtime
Creating Controls at Runtime
var
ButtonPtr: ^TButton;
procedure TForm2.Button1Click(Sender: TObject);
var i: integer;
begin
for i:= 1 to StrToInt(Edit1.Text) do
Begin
new(ButtonPtr);
ButtonPtr^:= TButton.Create(self);
ButtonPtr^.Parent:= Panel1;
ButtonPtr^.Left:= 100;
ButtonPtr^.Top:= i*40;
End;
end;
Creating Controls at Runtime
Creating Controls at Runtime
procedure TForm2.Button1Click(Sender: TObject);
var i: integer;
myButton: ^TButton;
begin
for i:= 1 to StrToInt(Edit1.Text) do
Begin
new(ButtonPtr);
ButtonPtr^:= TButton.Create(self);
ButtonPtr^.Caption:= 'Button' + IntToStr(i);
ButtonPtr^.Parent:= Panel1;
ButtonPtr^.Left:= 100;
ButtonPtr^.Top:= i*40;
End;
end;
Creating Controls at Runtime
Creating Controls at Runtime
Type TempPtr = ^ TForm;
TempArr = array [1..Cst] of TempPtr;
Var Arr:TempArr;
procedure TForm1.Button1Click(Sender: TObject);
Var i:integer;
begin
for i:=1 to Cst do
Begin
new(Arr[i]); // as he have said we need to New the ptr
Arr[i]^:= TForm.Create(self);
Arr[i]^.Show();// Now in every count a new form will be
// created and showed
End;
End;
Creating Controls at Runtime
Creating Controls at Runtime
Type TempPtr = ^ TForm;
TempArr = array [1..Cst] of TempPtr;
Var Arr:TempArr;
procedure TForm1.Button1Click(Sender: TObject);
Var i:integer;
begin
for i:=1 to Cst do
Begin
// new(Arr[i]);
Arr[i]^:= TForm.Create(self);
Arr[i]^.Show();// Now in every count a new form will be
// created and showed
End;
End;
Creating Controls at Runtime
Creating Controls at Runtime

Type
PtrTemp=^Rcd;
Rcd=record
ShapePtr:^Tshape;
Next:PtrTemp;
end;
Var ls,s,Cruiser:PtrTemp;
// we assume that we have the procedure INSERT already
Creating Controls at Runtime
// we assume that we have the procedure INSERT already
procedure TForm1.Timer1Timer(Sender: TObject);
Begin
new(s);
new(s^.ShapePtr);
s^.ShapePtr^:= TShape.Create(self);
s^.ShapePtr^.Parent:= Panel1;
s^.ShapePtr^.Show();
s^.ShapePtr^.width:=10;
insert(ls,s);
end;
Creating Controls at Runtime
// we assume that we have the procedure INSERT already
procedure TForm1.Timer1Timer(Sender: TObject);
Begin
new(s);
insert(ls,s);
new(s^.ShapePtr);
s^.ShapePtr^:= TShape.Create(self);
s^.ShapePtr^.Parent:= Panel1;
s^.ShapePtr^.Show();
s^.ShapePtr^.width:=10;
End;
Creating Controls at Runtime
// we assume that we have the procedure INSERT already
procedure TForm1.Button1Click(Sender: TObject);
Begin
Cruiser:=ls;
While (Cruiser<>nil) do
begin
Cruiser^.ShapePtr:= Shape1;
// Compile Errorincompatible types
Cruiser:= Cruiser^.Next;
end;
end;
Creating Controls at Runtime
// we assume that we have the procedure INSERT already
procedure TForm1.Button1Click(Sender: TObject);
Begin
new(Cruiser);
Cruiser:=ls;
While Cruiser<>nil do
begin
Cruiser^.ShapePtr^:= Shape1;
Cruiser:= Cruiser^.Next;
end;
end;
// This will result in all the list (ShapePtr) pointers to be
pointing to the static shape(Shape1).
Creating Controls at Runtime
// we assume that we have the procedure INSERT already
procedure TForm1.Button1Click(Sender: TObject);
Begin
new(Cruiser);
Cruiser:=ls;
While Cruiser<>nil do
begin
Cruiser^.ShapePtr^:= Button1;
Cruiser:= Cruiser^.Next;
end;
end;
// Compiler Error. incompatible types
// TButton and Tshape are different from each other
Creating Controls at Runtime
// we assume that we have the procedure INSERT already
procedure TForm1.Button1Click(Sender: TObject);
Begin
new(Cruiser);
Cruiser:=ls;
While Cruiser<>nil do
begin
Cruiser^.ShapePtr^.Width:= Cruiser^.ShapePtr^.Width+10;
Cruiser:= Cruiser^.Next;
end;
end;
// This will result in increase of the width of all
// shapes of the list by 10 Cool
To be continued..
See you!

More Related Content

What's hot (11)

Do...while loop structure
Do...while loop structureDo...while loop structure
Do...while loop structure
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
 
C++ loop
C++ loop C++ loop
C++ loop
 
Loop c++
Loop c++Loop c++
Loop c++
 
While loops
While loopsWhile loops
While loops
 
Loops c++
Loops c++Loops c++
Loops c++
 
Comp ppt (1)
Comp ppt (1)Comp ppt (1)
Comp ppt (1)
 
The Loops
The LoopsThe Loops
The Loops
 
While loop
While loopWhile loop
While loop
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 

Viewers also liked

Viewers also liked (9)

Geo gebra
Geo gebraGeo gebra
Geo gebra
 
Eng prac (2)
Eng prac (2)Eng prac (2)
Eng prac (2)
 
Delphi L08 Controls at Runtime P2
Delphi L08 Controls at Runtime P2Delphi L08 Controls at Runtime P2
Delphi L08 Controls at Runtime P2
 
Delphi L06 GDI Drawing
Delphi L06 GDI DrawingDelphi L06 GDI Drawing
Delphi L06 GDI Drawing
 
Stock ticker assignment b
Stock ticker assignment bStock ticker assignment b
Stock ticker assignment b
 
Aro
AroAro
Aro
 
Gamemaker
GamemakerGamemaker
Gamemaker
 
03 ch17 oligopoly
03 ch17 oligopoly03 ch17 oligopoly
03 ch17 oligopoly
 
Monopsony market structure
Monopsony market structureMonopsony market structure
Monopsony market structure
 

Similar to Delphi L07 Controls at Runtime P1

Psuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptxPsuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptxMattFlordeliza1
 
Delphi L03 Forms and Input
Delphi L03 Forms and InputDelphi L03 Forms and Input
Delphi L03 Forms and InputMohammad Shaker
 
Fundamental of Information Technology - UNIT 6
Fundamental of Information Technology - UNIT 6Fundamental of Information Technology - UNIT 6
Fundamental of Information Technology - UNIT 6Shipra Swati
 
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLabIntroduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLabCloudxLab
 
Exceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant BhabadExceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant Bhabadvasant Bhabad
 
Contiki introduction I.
Contiki introduction I.Contiki introduction I.
Contiki introduction I.Dingxin Xu
 
Converter - C- Language Program
Converter - C- Language ProgramConverter - C- Language Program
Converter - C- Language ProgramZuhaib Ali
 
maXbox Blix the Programmer
maXbox Blix the ProgrammermaXbox Blix the Programmer
maXbox Blix the ProgrammerMax Kleiner
 
In scilab Write a function named countDown that accepts a total time T.docx
In scilab Write a function named countDown that accepts a total time T.docxIn scilab Write a function named countDown that accepts a total time T.docx
In scilab Write a function named countDown that accepts a total time T.docxcarold12
 
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Sivaranjan Goswami
 
C++ Course - Lesson 1
C++ Course - Lesson 1C++ Course - Lesson 1
C++ Course - Lesson 1Mohamed Ahmed
 
19.Advanced Visual Basic Lab.pdf
19.Advanced Visual Basic Lab.pdf19.Advanced Visual Basic Lab.pdf
19.Advanced Visual Basic Lab.pdfvirox10x
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_recordskinan keshkeh
 

Similar to Delphi L07 Controls at Runtime P1 (20)

Psuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptxPsuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptx
 
Java calculator
Java calculatorJava calculator
Java calculator
 
Delphi L03 Forms and Input
Delphi L03 Forms and InputDelphi L03 Forms and Input
Delphi L03 Forms and Input
 
Fundamental of Information Technology - UNIT 6
Fundamental of Information Technology - UNIT 6Fundamental of Information Technology - UNIT 6
Fundamental of Information Technology - UNIT 6
 
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLabIntroduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
 
The timer use
The timer useThe timer use
The timer use
 
Exceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant BhabadExceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant Bhabad
 
Contiki introduction I.
Contiki introduction I.Contiki introduction I.
Contiki introduction I.
 
Converter - C- Language Program
Converter - C- Language ProgramConverter - C- Language Program
Converter - C- Language Program
 
C# Loops
C# LoopsC# Loops
C# Loops
 
maXbox Blix the Programmer
maXbox Blix the ProgrammermaXbox Blix the Programmer
maXbox Blix the Programmer
 
SPF WinForm Programs
SPF WinForm ProgramsSPF WinForm Programs
SPF WinForm Programs
 
Os unit 3
Os unit 3Os unit 3
Os unit 3
 
In scilab Write a function named countDown that accepts a total time T.docx
In scilab Write a function named countDown that accepts a total time T.docxIn scilab Write a function named countDown that accepts a total time T.docx
In scilab Write a function named countDown that accepts a total time T.docx
 
Foundations of Programming Part I
Foundations of Programming Part IFoundations of Programming Part I
Foundations of Programming Part I
 
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
 
C++ Course - Lesson 1
C++ Course - Lesson 1C++ Course - Lesson 1
C++ Course - Lesson 1
 
19.Advanced Visual Basic Lab.pdf
19.Advanced Visual Basic Lab.pdf19.Advanced Visual Basic Lab.pdf
19.Advanced Visual Basic Lab.pdf
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records
 

More from Mohammad Shaker

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian GraduateMohammad Shaker
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Mohammad Shaker
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyMohammad Shaker
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015Mohammad Shaker
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game DevelopmentMohammad Shaker
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesMohammad Shaker
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - ColorMohammad Shaker
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - TypographyMohammad Shaker
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingMohammad Shaker
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and ThreadingMohammad Shaker
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSMohammad Shaker
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsMohammad Shaker
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsMohammad Shaker
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and GamingMohammad Shaker
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / ParseMohammad Shaker
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesMohammad Shaker
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes Mohammad Shaker
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and AdaptersMohammad Shaker
 

More from Mohammad Shaker (20)

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with Psychology
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game Development
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - Color
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - Typography
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
 
Android L05 - Storage
Android L05 - StorageAndroid L05 - Storage
Android L05 - Storage
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and Threading
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and Gaming
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / Parse
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and Adapters
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
 

Recently uploaded

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Recently uploaded (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Delphi L07 Controls at Runtime P1

  • 1. Intro to Event-driven Programming and Forms with Delphi L07 - Creating Controls at Runtime Part 1 Mohammad Shaker mohammadshakergtr.wordpress.com Intro to Event-driven Programming and Forms with Delphi @ZGTRShaker 2010, 2011, 2012
  • 2.
  • 3. Creating Controls at Runtime • Let’s have the following form design
  • 4. Creating Controls at Runtime •We declare the “control” like any other variable var i: Integer; var TempShape:TShape; procedure TForm2.Button1Click(Sender: TObject); begin // Now we initialize the shape to use it as a NORMAL // one TempShape:= TShape.Create(self); End;
  • 5. Creating Controls at Runtime • Compiler Error – Tshape is undeclared type • So don’t forget to add ExtCtrls. uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
  • 6. Creating Controls at Runtime •Compile and Run but no shape outputted after writing the following code. – What’s messing? Var TempShape:Tshape; procedure TForm2.Button1Click(Sender: TObject); begin // Now we initialize the shape to use it as a NORMAL // one TempShape:= Tshape.Create(self); End;
  • 7. Creating Controls at Runtime procedure TForm2.Button1Click(Sender: TObject); begin TempShape:= Tshape.Create(self); TempShape.Parent:= Panel1; end;
  • 8. Creating Controls at Runtime procedure TForm2.Button1Click(Sender: TObject); begin TempShape:= Tshape.Create(self); TempShape.Parent:= Panel1; TempShape.Shape:= stEllipse; TempShape.Height:= 100; TempShape.Width:= 50; TempShape.Left:= 100; TempShape.Top:= 50; TempShape.Brush.Color:= 255; end;
  • 10. Creating Controls at Runtime • Let’s have the following form design
  • 11. Creating Controls at Runtime procedure TForm2.Button1Click(Sender: TObject); var i: integer; ShapeArr: Array [1..5] of TShape; begin for i:= 1 to 5 do Begin ShapeArr[i]:= TShape.Create(self); ShapeArr[i].Parent:= Panel1; ShapeArr[i].Brush.Color:= i*100; ShapeArr[i].Left:= 100; ShapeArr[i].Top:= i*40; End; end;
  • 13.
  • 15. Creating Controls at Runtime var ButtonPtr: ^TButton; procedure TForm2.Button1Click(Sender: TObject); var i: integer; begin for i:= 1 to StrToInt(Edit1.Text) do Begin new(ButtonPtr); ButtonPtr^:= TButton.Create(self); ButtonPtr^.Parent:= Panel1; ButtonPtr^.Left:= 100; ButtonPtr^.Top:= i*40; End; end;
  • 17. Creating Controls at Runtime procedure TForm2.Button1Click(Sender: TObject); var i: integer; myButton: ^TButton; begin for i:= 1 to StrToInt(Edit1.Text) do Begin new(ButtonPtr); ButtonPtr^:= TButton.Create(self); ButtonPtr^.Caption:= 'Button' + IntToStr(i); ButtonPtr^.Parent:= Panel1; ButtonPtr^.Left:= 100; ButtonPtr^.Top:= i*40; End; end;
  • 19. Creating Controls at Runtime Type TempPtr = ^ TForm; TempArr = array [1..Cst] of TempPtr; Var Arr:TempArr; procedure TForm1.Button1Click(Sender: TObject); Var i:integer; begin for i:=1 to Cst do Begin new(Arr[i]); // as he have said we need to New the ptr Arr[i]^:= TForm.Create(self); Arr[i]^.Show();// Now in every count a new form will be // created and showed End; End;
  • 21. Creating Controls at Runtime Type TempPtr = ^ TForm; TempArr = array [1..Cst] of TempPtr; Var Arr:TempArr; procedure TForm1.Button1Click(Sender: TObject); Var i:integer; begin for i:=1 to Cst do Begin // new(Arr[i]); Arr[i]^:= TForm.Create(self); Arr[i]^.Show();// Now in every count a new form will be // created and showed End; End;
  • 23. Creating Controls at Runtime Type PtrTemp=^Rcd; Rcd=record ShapePtr:^Tshape; Next:PtrTemp; end; Var ls,s,Cruiser:PtrTemp; // we assume that we have the procedure INSERT already
  • 24. Creating Controls at Runtime // we assume that we have the procedure INSERT already procedure TForm1.Timer1Timer(Sender: TObject); Begin new(s); new(s^.ShapePtr); s^.ShapePtr^:= TShape.Create(self); s^.ShapePtr^.Parent:= Panel1; s^.ShapePtr^.Show(); s^.ShapePtr^.width:=10; insert(ls,s); end;
  • 25. Creating Controls at Runtime // we assume that we have the procedure INSERT already procedure TForm1.Timer1Timer(Sender: TObject); Begin new(s); insert(ls,s); new(s^.ShapePtr); s^.ShapePtr^:= TShape.Create(self); s^.ShapePtr^.Parent:= Panel1; s^.ShapePtr^.Show(); s^.ShapePtr^.width:=10; End;
  • 26. Creating Controls at Runtime // we assume that we have the procedure INSERT already procedure TForm1.Button1Click(Sender: TObject); Begin Cruiser:=ls; While (Cruiser<>nil) do begin Cruiser^.ShapePtr:= Shape1; // Compile Errorincompatible types Cruiser:= Cruiser^.Next; end; end;
  • 27. Creating Controls at Runtime // we assume that we have the procedure INSERT already procedure TForm1.Button1Click(Sender: TObject); Begin new(Cruiser); Cruiser:=ls; While Cruiser<>nil do begin Cruiser^.ShapePtr^:= Shape1; Cruiser:= Cruiser^.Next; end; end; // This will result in all the list (ShapePtr) pointers to be pointing to the static shape(Shape1).
  • 28. Creating Controls at Runtime // we assume that we have the procedure INSERT already procedure TForm1.Button1Click(Sender: TObject); Begin new(Cruiser); Cruiser:=ls; While Cruiser<>nil do begin Cruiser^.ShapePtr^:= Button1; Cruiser:= Cruiser^.Next; end; end; // Compiler Error. incompatible types // TButton and Tshape are different from each other
  • 29. Creating Controls at Runtime // we assume that we have the procedure INSERT already procedure TForm1.Button1Click(Sender: TObject); Begin new(Cruiser); Cruiser:=ls; While Cruiser<>nil do begin Cruiser^.ShapePtr^.Width:= Cruiser^.ShapePtr^.Width+10; Cruiser:= Cruiser^.Next; end; end; // This will result in increase of the width of all // shapes of the list by 10 Cool