SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
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!

Contenu connexe

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

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Plus 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
 

Plus 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
 

Dernier

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 

Dernier (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 

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