SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler 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!

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sectoritnewsafrica
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 

Último (20)

The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 

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