Title: The structure of a Delphi program
1The structure of a Delphi program
2unit 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.
3unit 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
4unit 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
5unit 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
6unit 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.
7unit 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.
8Important properties of images
9unit 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.
10Click the mouse on the button
procedure TForm1.loadClick(Sender
TObject) begin image1.Picture.LoadFromFile('ap
hro2.bmp') end
11width
width
height
height
Form1.Image1.picture.bitmap
Form1.Image1
12procedure TForm1.loadClick(Sender
TObject) begin image1.Picture.LoadFromFile('ap
hro2.bmp') image1.Stretchtrue end
13procedure 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
15Drag and drop
Demo
16unit 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
17implementation 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.
18Transparency
Demo