Delivery between interface and business logic in Delphi
J Xue (zhuam)[email protected]
Before I started Delphi software development, I was engaged in Java software development. I learned a lot of software design ideals from the Java open source community. This may be the reward I got from Java! Broadening my horizons!
The recent project was developed with Delphi, so I looked at Delphi again. In a month, I read about 4 Delphi books. When I was working on the Delphi project, I even used the DELPHI syntax and JAVA ideas. I feel a little tired when I develop and design the software! Ah, let’s talk less, let’s get to the point!
DELPHI is an IDE for rapid software development. Usually, PRogrammer first draws a View (interface), and then writes Source Code in the corresponding event to see the example:
1. For example, if I want to insert a record into the database, this is the usual way!
SQL Example: Insert Into ExampleTable1 (Field1, Field2, Field3) Values(Values1, Values2, Values3)
Now suppose there are three TEXT controls on this DELPHI form, name is Frist, Second, and Three respectively
Here I use three different methods to insert data into the database:
1. Insert directly
client ------------> Database
Insert Into ExampleTable1 (Field1, Field2, Field3) Values(Frist.text, Second.text, Three.text)
2. Indirect insertion
client ---(Text pass) ---> dataClass -------> Database
It means that the form data is saved first into a data class, and then the user takes the data from this data class and transfers the data.
Pass to the database
Notice:
The form control directly stores data into the dataClass data class through TEXT.
This dataClass is only used to store data state, and it is full of attributes and has no business logic implementation!
as follows:
{-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
author:zhuam
date:2004/09/04
type:class
property:all AssociatorRunBean Information Set Mothed
description: Used to save member's driving license information,
--------------------------------------------------------------------------------------------------------------------------------
type
TAssociatorRunBean=class(TObject)
Private
FKiloMetre: Double;
FCarNumber: string;
FNumber17: string;
FCarColor: string;
FAssociatorID: string;
FCarCapacity: string;
FFrameNumber: string;
FEngineNumber: string;
FAvailabilityDate: TDate;
FRegisterDate: TDate;
FBackPicture:TImage;
FFrontPicture: TImage;
FLeftPicture: TImage;
FRightPicture: TImage;
function getBackPicture: TImage;
function getFrontPicture: TImage;
function getLeftPicture: TImage;
function getRightPicture: TImage;
procedure setAssociatorID(const Value: string);
procedure setAvailabilityDate(const Value: TDate);
procedure setBackPicture(const Value: TImage);
procedure setCarCapacity(const Value: string);
procedure setCarColor(const Value: string);
procedure setCarNumber(const Value: string);
procedure setEngineNumber(const Value: string);
procedure setFrameNumber(const Value: string);
procedure setFrontPicture(const Value: TImage);
procedure setKiloMetre(const Value: Double);
procedure setLeftPicture(const Value: TImage);
procedure setNumber17(const Value: string);
procedure setRegisterDate(const Value: TDate);
procedure setRightPicture(const Value: TImage);
public
constructor create;
Destructor destroy;override;
property AssociatorID:string read FAssociatorID write setAssociatorID; // Member number
property CarNumber:string read FCarNumber write setCarNumber; // license plate number
property CarColor:string read FCarColor write setCarColor; //Car Color
property CarMode:string read FCarColor write setCarColor; //Model
property EngineNumber:string read FEngineNumber write setEngineNumber; //Engine number
property FrameNumber:string read FFrameNumber write setFrameNumber; //frame number
property CarCapacity:string read FCarCapacity write setCarCapacity; //displacement
property Number17:string read FNumber17 write setNumber17; //17-digit number
property KiloMetre:Double read FKiloMetre write setKiloMetre; //Kilometres
property RegisterDate:TDate read FRegisterDate write setRegisterDate; //Registration date
property AvailabilityDate:TDate read FAvailabilityDate write setAvailabilityDate; //Efficient date
property FrontPicture:TImage read getFrontPicture write setFrontPicture;
property BackPicture: TImage read getBackPicture write setBackPicture;
property LeftPicture:TImage read getLeftPicture write setLeftPicture;
property RightPicture: TImage read getRightPicture write setRightPicture;
end;
Insert Into ExampleTable1 (Field1, Field2, Field3) Values(AssociatorRunBean.Frist,AssociatorRunBean.Second,AssociatorRunBean.text)
3. Indirect insertion
client ---(custom property delivery) ---> dataClass -------> Database
It means that the form data is saved first into a data class, and then the user takes the data from this data class and transfers the data.
Pass to the database
Notice:
The form control directly stores data into the (dataClass) data class through a custom property.
This dataClass is only used to store data state, and it is full of attributes and has no business logic implementation!
Insert Into ExampleTable1 (Field1, Field2, Field3) Values(AssociatorRunBean.Frist,AssociatorRunBean.Second,AssociatorRunBean.text)
Speaking of this, someone will ask me, what is the significance of realizing this way! Careful comrades may have noticed it!
This is a way to separate the Delphi interface from the business logic.