SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
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!

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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
 

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

Similar 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
 

Más 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
 

Más 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

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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
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
 

Último (20)

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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
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...
 

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