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

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
 
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
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Último (20)

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
 
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
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

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