The structure of a Delphi program - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

The structure of a Delphi program

Description:

In the type section you define the objects you will use in your program ... In the var section you give the names of the variables you will use, and their types. ... – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 19
Provided by: ianth3
Category:

less

Transcript and Presenter's Notes

Title: The structure of a Delphi program


1
The structure of a Delphi program
2
unit imageprops interface uses Windows,
Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls,
ExtCtrls type TForm1 class(TForm)
Image1 TImage load TButton procedure
loadClick(Sender TObject) private
Private declarations public Public
declarations end var Form1
TForm1 implementation R .dfm procedure
TForm1.loadClick(Sender TObject) begin
image1.Picture.LoadFromFile('aphro2.bmp') end en
d.
A program in Delphi is divided into sections.
3
unit imageprops interface uses Windows,
Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls,
ExtCtrls type TForm1 class(TForm)
Image1 TImage load TButton procedure
loadClick(Sender TObject) private
Private declarations public Public
declarations end var Form1
TForm1 implementation R .dfm procedure
TForm1.loadClick(Sender TObject) begin
image1.Picture.LoadFromFile('aphro2.bmp') end en
d.
interface
implementation
4
unit imageprops interface uses Windows,
Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls,
ExtCtrls type TForm1 class(TForm)
Image1 TImage load TButton procedure
loadClick(Sender TObject) private
Private declarations public Public
declarations end var Form1
TForm1 implementation R .dfm procedure
TForm1.loadClick(Sender TObject) begin
image1.Picture.LoadFromFile('aphro2.bmp') end en
d.
In the Uses section you tell the compiler what
other units to include
5
unit imageprops interface uses Windows,
Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls,
ExtCtrls type TForm1 class(TForm)
Image1 TImage load TButton procedure
loadClick(Sender TObject) private
Private declarations public Public
declarations end var Form1
TForm1 implementation R .dfm procedure
TForm1.loadClick(Sender TObject) begin
image1.Picture.LoadFromFile('aphro2.bmp') end en
d.
In the type section you define the objects you
will use in your program
6
unit imageprops interface uses Windows,
Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls,
ExtCtrls type TForm1 class(TForm)
Image1 TImage load TButton procedure
loadClick(Sender TObject) private
Private declarations public Public
declarations end var Form1
TForm1 implementation R .dfm procedure
TForm1.loadClick(Sender TObject) begin
image1.Picture.LoadFromFile('aphro2.bmp') end en
d.
In the var section you give the names of the
variables you will use, and their types.
7
unit imageprops interface uses Windows,
Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls,
ExtCtrls type TForm1 class(TForm)
Image1 TImage load TButton procedure
loadClick(Sender TObject) private
Private declarations public Public
declarations end var Form1
TForm1 implementation R .dfm procedure
TForm1.loadClick(Sender TObject) begin
image1.Picture.LoadFromFile('aphro2.bmp') end en
d.
The actual program is in the implementation
section. The header of each procedure also
appears in the interface section.
8
Important properties of images
9
unit imageprops interface uses Windows,
Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls,
ExtCtrls type TForm1 class(TForm)
Image1 TImage load TButton procedure
loadClick(Sender TObject) private
Private declarations public Public
declarations end var Form1
TForm1 implementation R .dfm procedure
TForm1.loadClick(Sender TObject) begin
image1.Picture.LoadFromFile('aphro2.bmp') end en
d.
10
Click the mouse on the button
procedure TForm1.loadClick(Sender
TObject) begin image1.Picture.LoadFromFile('ap
hro2.bmp') end
11
width
width
height
height
Form1.Image1.picture.bitmap
Form1.Image1
12
procedure TForm1.loadClick(Sender
TObject) begin image1.Picture.LoadFromFile('ap
hro2.bmp') image1.Stretchtrue end
13
procedure TForm1.loadClick(Sender
TObject) begin image1.Picture.LoadFromFile('ap
hro2.bmp') image1.heightimage1.picture.bitma
p.height image1.widthimage1.picture.bitmap.w
idth end
14
(left,top)
(left,top)
procedure TForm1.loadClick(Sender
TObject) begin image1.Picture.LoadFromFile('ap
hro2.bmp') image1.Stretchtrue end
procedure TForm1.loadClick(Sender
TObject) begin image1.Picture.LoadFromFile('ap
hro2.bmp') image1.Stretchtrue
image1.Leftimage1.Left100 end
15
Drag and drop
Demo
16
unit testdrag interface uses Windows,
Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, ExtCtrls,
StdCtrls type TForm1 class(TForm)
Image1 TImage Button1 TButton Image2
TImage procedure Button1Click(Sender
TObject) procedure FormDragDrop(Sender,
Source TObject X, Y Integer) procedure
FormDragOver(Sender, Source TObject X, Y
Integer State TDragState var Accept Boolean)
procedure Image1MouseDown(Sender TObject
Button TMouseButton Shift TShiftState X, Y
Integer) procedure Image2MouseDown(Sender
TObject Button TMouseButton Shift
TShiftState X, Y Integer) private
Private declarations public Public
declarations end var Form1 TForm1
oldx,oldyinteger mousetmouse
dragstartx,dragstartyinteger
_draggingboolean
17
implementation R .dfm procedure
TForm1.FormDragDrop(Sender, Source TObject X,
Y Integer) begin if Source is TImage then
begin TImage(Source).Left X
TImage(Source).Top Y _draggingfalse
end end procedure TForm1.FormDragOver(Sender,
Source TObject X, Y Integer State
TDragState var Accept Boolean) begin
Accept (Source is TImage) if accept then
_draggingtrue end procedure
TForm1.Image1MouseDown(Sender TObject Button
TMouseButton Shift TShiftState X, Y Integer)
begin if (ssCtrl in Shift) and
not(_dragging) then Image1.BeginDrag(True)
end procedure TForm1.Image2MouseDown(Sender
TObject Button TMouseButton Shift
TShiftState X, Y Integer) begin if (ssCtrl
in Shift) and not(_dragging) then
Image2.BeginDrag(True) end procedure
TForm1.Button1Click(Sender TObject) begin
image1.Picture.LoadFromFile('aphro2.bmp')
image2.Picture.LoadFromFile('aphro2.bmp') end en
d.
18
Transparency
Demo
Write a Comment
User Comments (0)
About PowerShow.com