Important syntax and OO features of Delphi-automotive jobs

Source: Internet
Author: User

Writing automobiles requires several categories such as automobiles, steering wheel, body, engine, and brakes.

Simulate a process from start to end and output the state changes of the car.

Several types of vehicles are also implemented: Audi A4, Mercedes-Benz C200, and Audi Q7.

Thoughts:

1. Write the steering wheel, body, engine, and brakes into one category respectively;

2. The above category is a member of the automobile category;

3. Add process functions such as start, drive, and stop for the vehicle and declare them as virtual;

4,Audi A4, Mercedes-Benz C200, Audi Q7Inherited from the vehicle class and overwrittenAuto Start, drive, stop and other process functions.

Class list:

Steering wheel type:

{Automotive unit name: steeringwheel Author: huyp Date: 06-September-2012 purpose: car parts steering wheel class history: V1.0 finished} unit steeringwheel; interface {steeringwheel steering wheel type} type tsteeringwheel = class private diameter: real; // steering wheel diameter material: string; Public {public declarations} end; implementationend.

Body Type:

{Automotive unit name: carbody Author: huyp Date: 06-September-2012 purpose: Automotive Parts car body class history: V1.0 detail} unit carbody; interface {carbody} type tcarbody = class private color: string; style: string; Length: real; weight: real; Public {public declarations} end; implementationend.

Engine type:

{Component unit name: Engine Author: huyp Date: 06-August 1, August-2012 purpose: car parts engine class history: V1.0 detail} unit engine; interface {engine} type tengine = class private numofcylinder: integer; // Number of cylinders numofairvalve: integer; // Number of valves power: real; Public {public declarations} end; implementationend.

Brakes:

{Automotive unit name: Brake Author: huyp Date: 06-September-2012 purpose: Automobile Parts brake class history: V1.0 detail} unit brake; interface {brake} type tbrake = class private safety: real; // security factor public {public declarations} end; implementationend.

Automobile:

{Automobile unit name: basecar Author: huyp Date: 06-September-2012 purpose: basecar class is a basic automobile class. It has the general attributes of a car and is the basic class of other automobile classes. History: v1.0 drivers} unit basecar; interfaceuses messages, brake, carbody, steeringwheel, engine, dialogs; {vehicle class} type tcar = class private name: string; Size: string; manufacture: string; price: real; Public {public declarations} custom: tsteeringwheel; // steering wheel Class Object huypcarbody: tcarbody; // body Class Object huypengine: tengine; // engine Class Object huypbrake: tbrake; // brake Class Object procedure starting; virtual; // simulate the auto start function, which can be quilt class override procedure driving; virtual; // simulate the car driving function, and quilt class override procedure stopping; virtual; // simulate the car stop function, which can be quilt override end; implementationvar huypcar: tcar; {export procedure: Starting Author: huyp Date: 06-August-2012 arguments: None result: none funtion: simulate auto start ---------------------------------------------------------------------------------} procedure tcar. starting; begin messagedlg ('this is a car, it's time to go ', mtinformation, [mbok, mbcancel], 0); end; {export procedure: Driving Author: huyp Date: 06-February-2012 arguments: None result: None funtion: Simulated car driving ---------------------------------------------------------------------------} procedure tcar. driving; begin messagedlg ('this is a car, it's driving ', mtinformation, [mbok], 0); end; {define procedure: Stopping Author: huyp Date: 06-May 17-2012 arguments: None result: None funtion: Simulated car stop -----------------------------------------------------------------------------} procedure tcar. stopping; begin messagedlg ('this is a car, it's stopping', mtinformation, [mbok], 0); end.

The following classes are inherited from the automobile class:

Audi A4:

{Custom unit name: audia4 Author: huyp Date: 06-August-2012 purpose: inherits from the basecar audia4, inherits the attributes of a general car, and reloads the basecar startup, driving and stopping functions history: V1.0 leading} unit audia4; interfaceuses basecar, dialogs; {audia4} type taudia4 = Class (tcar) Private procedure starting; override; // rewrite the vehicle start Function Procedure driving; override; // rewrite the vehicle stop Function Procedure stopping; override; // rewrite the car stop function public {public declarations} end; implementationvar myaudia4: taudia4; {export procedure: Starting Author: huyp Date: 06-September-2012 arguments: None result: None function: Simulate audia4 startup function prepare} procedure taudia4.starting; begin messagedlg ('this is audia4, it's time to go, mtinformation, [mbok, mbcancel], 0); end; {export procedure: Driving Author: huyp Date: 06-August-2012 arguments: none result: None function: Simulated Driving startup function success} procedure taudia4.driving; begin messagedlg ('this is audia4, it's time to go ', mtinformation, [mbok, mbcancel], 0); end; {export procedure: Stopping Author: huyp Date: 06-August-2012 arguments: None result: None function: Simulate audia4 stop function seek} procedure taudia4.stopping; begin messagedlg ('this is audia4, it's time to go ', mtinformation, [mbok, mbcancel], 0); end.

Mercedes-Benz C200:

{Worker Unit name: benzc200 Author: huyp Date: 06-August-2012 purpose: inherits the benzc200 from basecar, inherits the attributes of a general car, and reloads the start of basecar, driving and stopping functions history: V1.0 leading} unit benzc200; interfaceuses basecar, dialogs; {benzc200} type tbenzc200 = Class (tcar) Private procedure starting; override; // rewrite the vehicle start Function Procedure driving; override; // rewrite the vehicle stop Function Procedure stopping; override; // rewrite the car stop function public {public declarations} end; implementationvar mybenzc200: tbenzc200; {export procedure: Starting Author: huyp Date: 06-August-2012 arguments: None result: None function: Simulate benzc200 startup function handler} procedure tbenzc200.starting; begin messagedlg ('this is benzc200, it's time to go, mtinformation, [mbok, mbcancel], 0); end; {export procedure: Driving Author: huyp Date: 06-August-2012 arguments: none result: None function: Simulate benzc200 driving function export} procedure tbenzc200.driving; begin messagedlg ('this is benzc200, it's time to go ', mtinformation, [mbok, mbcancel], 0); end; {export procedure: Stopping Author: huyp Date: 06-September-2012 arguments: None result: None function: Simulate benzc200 stop function else} procedure tbenzc200.stopping; begin messagedlg ('this is benzc200, it's time to go ', mtinformation, [mbok, mbcancel], 0); end.

Audi Q7:

{Custom unit name: audiq7 Author: huyp Date: 06-September-2012 purpose: inherits audiq7 from basecar, inherits attributes of a general car, and reloads basecar startup, driving and stopping functions history: V1.0 placement} unit audiq7; interfaceuses basecar, dialogs; {audiq7} type taudiq7 = Class (tcar) Private procedure starting; override; // rewrite the vehicle start Function Procedure driving; override; // rewrite the vehicle stop Function Procedure stopping; override; // rewrite the car stop function public {public declarations} end; implementationvar myaudiq7: taudiq7; {export procedure: Starting Author: huyp Date: 06-September-2012 arguments: None result: None function: Simulate audiq7 startup function prepare} procedure taudiq7.starting; begin messagedlg ('this is audiq7, it's time to go, mtinformation, [mbok, mbcancel], 0); end; {export procedure: Driving Author: huyp Date: 06-August-2012 arguments: none result: None function: Simulate audiq7 driving function generator} procedure taudiq7.driving; begin messagedlg ('this is audiq7, it's time to go ', mtinformation, [mbok, mbcancel], 0); end; {stopping procedure: Stopping Author: huyp Date: 06-September-2012 arguments: None result: None function: Simulating audiq7 stop function seek} procedure taudiq7.stopping; begin messagedlg ('this is audiq7, it's time to go ', mtinformation, [mbok, mbcancel], 0); end.

Call the methods of these classes in the main window:

{Vehicle unit name: mycar Author: huyp Date: 06-September-2012 purpose: Call tbasecar taudia4 taudiq7 tbenzc200 class car simulation process history: V1.0 workshop} unit mycar; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, brake, carbody, steeringwheel, engine, basecar, audia4, audiq7, benzc200; type tcarform = Class (tform) btncarprocess: tbutton; // The general vehicle operation button btnaudia4: tbutton; // audia4 OPERATION button btnbenzc200: tbutton; // benzc200 OPERATION button tbutton; // audiq7 OPERATION button procedure btnaudia4click (Sender: tobject); // simulate Audi A4 process procedure finished (Sender: tobject); // simulate Audi Q7 process procedure btnbenzc200click (Sender: tobject); // simulate the C-Benz C200 process procedure btncarprocessclick (Sender: tobject); // simulate the general vehicle process private {private Declarations} public {public declarations} end; var carform: tcarform; huypcar: tcar; implementation {$ R *. DFM} {export procedure: btnaudia4click Author: huyp Date: 06-August-2012 arguments: Sender: tobject result: None function: simulates the process from starting to stopping Audi A4, call the taudia4 class member method -----------------------------------------------------------------------------} procedure tcarform. btnaudia4click (Sender: tobject); var myaudia4: taudia4; begin myaudia4: = taudia4.create; example; end; {Example procedure: Example Author: huyp Date: august-2012 arguments: Sender: tobject result: None function: simulates the process of Audi Q7 from start to stop and calls the member method of taudiq7} procedure tcarform. values (Sender: tobject); var myaudiq7: taudiq7; begin myaudiq7: = taudiq7.create; values; myaudiq7.free; end; {your procedure: Your Author: huyp date: august-2012 arguments: Sender: tobject result: None function: Simulate the benzc200 process from start to stop, call the member method of the tbenzc200 class} procedure tcarform. values (Sender: tobject); var mybenzc200: tbenzc200; begin mybenzc200: = values; end; {export procedure: btncarprocessclick Author: huyp Date: 06-July 22, August-2012 arguments: Sender: tobject result: None function: simulate the process from start to stop of the car and call the member method of the tcar class prepare} procedure tcarform. btncarprocessclick (Sender: tobject); var mycar: tcar; begin mycar: = tcar. create; mycar. starting; mycar. driving; mycar. stopping; mycar. free; end.

Encoding specification:

1. SetSteering wheel, body, engine, brakes, automobiles,Audi A4, Mercedes-Benz C200, and Audi Q7Written in a separate unit file;

2. Name

1) The name of the unit file must be meaningful;

2) The Control name must comply with the encoding specifications, such as the button prefix BTN.

3) add T to the class name to indicate that it is a model;

3. Notes

1) Add a header comment to each unit file;

2) add comments to each variable declaration and function declaration;

3) add comments to process and function implementation according to gexpert function standards;

Problems:

1. How can I associate classes in a unit file and call each other?

Add the name of the unit file after uses.

2. What are the parameters of these classes?

Make full use of the information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.