Delphi Éè¼Æģʽ£º¡¶HeadFirstÉè¼Æģʽ¡·Delphi7´úÂë
ûÓÐÓ¦ÓÃ״̬ģʽµÄ´úÂë
1. ¹¤³ÌÎļþ
program Project1;
{$APPTYPE CONSOLE}
uses
uGumballMachine in 'uGumballMachine.pas';
var
aGumballMachine: TGumballMachine;
begin
aGumballMachine := TGumballMachine.Create(5);
aGumballMachine.InsertQuarter;
aGumballMachine.TurnCrank;
Writeln;
aGumballMachine.InsertQuarter;
aGumballMachine.EjectQuarter;
aGumballMachine.TurnCrank;
Writeln;
aGumballMachine.InsertQuarter;
aGumballMachine.TurnCrank;
aGumballMachine.InsertQuarter;
aGumballMachine.TurnCrank;
aGumballMachine.EjectQuarter;
Writeln;
aGumballMachine.InsertQuarter;
aGumballMachine.InsertQuarter;
aGumballMachine.TurnCrank;
aGumballMachine.InsertQuarter;
aGumballMachine.TurnCrank;
aGumballMachine.InsertQuarter;
aGumballMachine.TurnCrank;
aGumballMachine.Free;
Readln;
end.
2.µ¥ÔªÎļþ
unit uGumballMachine;
interface
type
TGumballMachine = class(TObject)
private
FState: Integer;
FCount: Integer;
public
constructor Create(aCount: Integer);
procedure InsertQuarter;
procedure EjectQuarter;
procedure TurnCrank;
procedure Dispense;
end;
implementation
const
SOLD_OUT = 0;
NO_QUARTER = 1;
HAS_QUARTER = 2;
SOLD = 3;
{ TGumballMachine }
constructor TGumballMachine.Create(aCount: Integer);
begin
FCount := aCount;
FState := SOLD_OUT;
if FCount > 0 then
FState := NO_QUARTER;
end;
procedure TGumballMachine.Dispense;
begin
if FState = SOLD then
begin
Writeln('A gumball comes rolling out the slot');
FCount := FCount - 1;
if FCount = 0 then
begin
Writeln('Oops, out of Gumballs');
FState := SOLD_OUT;
end
else
FState := NO_QUARTER;
end;
if FState = NO_QUARTER then
Writeln('You need to pay first');
if FState = SOLD_OUT then
Writeln('No gumball dispensed');
if FState = HAS_QUARTER then
Writeln('No gumball dispensed');
end;
procedure TGumballMa
Ïà¹ØÎĵµ£º
Python , Delphi , Loki Èý¸öµ¥´ÊÓÐȤµÄÀ´Ô´
Ðí¶à³ÌÐòÉè¼ÆÓïÑԺͿª·¢¹¤¾ßÒÔ¼°¿âµÄÃû×Ö¶¼À´Ô´ÓëÉñ»°£¬ÆÄÓÐÒâ˼£º
°¢²¨ÂÞÊÇͬʱ³öÏÖÔÚÏ£À°ºÍÂÞÂíÉñ»°ÖеİÂÁÖÅÁ˹ʮ¶þ´óÉñÖ®Ò»¡£Ëû³ýÁËÓµÓÐÌ«ÑôÉñµÄÉí·Ö£¬Í¬Ê±»¹ÓÐÔ¤ÑÔ¡¢ÒÕÊõ¡¢Ò½ÊõÖ®ÉñµÄ³ÆºÅ¡£°¢²¨ÂÞÊÇÖæ˹ºÍÀÖ¶äµÄ¶ù×Ó£¬ºÍ°¢µÙÃÛ˹ÊÇË ......
ÍƼö¸ø´ó¼Ò[url=DELPHIÉî¶È̽Ë÷ £¨µÚ2°æ£©PDFµç×ÓÊé][/url]
ÒòΪÐèҪǰ¼¸ÌìÔÚÍøÉÏËÑËѹýÕâ±¾ÊéÊ飬¿ÉûÓУ¬Ô´Âëµ¹ÊÇÓУ¬½ñÌì´ò¿ª¾³£È¥µÄÍøÕ¾£¬¾ÓÈ»·¢ÏÖÌṩÏÂÔØÁË£¬Õâ¸öÍøÕ¾×Ô¼º²î²»¶àÿÌ춼Ҫ´ò¿ª¿´¿´£¬Õ⼸ÌìæºýÍ¿ÁË£¬¾ÓȻûÓп´µ½£¬ÔÚÕâÍƼö¸ø´ó¼Ò£¬ÄÜÏÂÔصģ¬ËٶȺܿ졣
[url=http://www.delphifans.com/Soft ......
//¶¨ÒåMyClass
TMyClass = class
GUID: string;
Name: string;
bSex: Boolean;
Tel : string;
end;
//È¡Öµ
var
obj: TMyClass;
begin
obj := TMyClass.Create;
with Memo1.Lines do
begin
Add('¶ÔÏó´óС:' + IntToStr(obj.InstanceSize));
Add('¶ÔÏóËùÔÚµØÖ·£º'+ ......
¼Ì³ÐÊÇΪÁ˱íÏÖÀàÓëÀàÖ®¼ä“ÊÇÒ»ÖÖ”¹Øϵ£¬ÊǶà̬´æÔڵĻù´¡£¬¼Ì³ÐÊÇÃæÏó¶ÔÏó±Ø²»¿ÉÉٵĻù´¡£¬Ö»Ö§³Ö·â×°¶ø²»Ö§³Ö¼Ì³ÐµÄÓïÑÔÖ»ÄܳÆΪ“»ùÓÚ¶ÔÏ󔣨Object-Based£©Ãæ·ÇÃæÏò¶ÔÏó“Object-Oriented”;
Object PascalÖ»Ö§³Öµ¥¼Ì³Ð£¬Ò²¾ÍÊÇÒ»¸öÅÉÉúÀàÖ»ÄÜÓÐÒ»¸ö»ùÀà
µ«¿ÉÒÔʵÏÖ¶à¸ö½Ó¿Ú ......
1. ÃüÁîµÄ½ÓÊÜÕß
unit uReceiveObject;
interface
type
TLight = class(TObject)
public
procedure Open;
procedure Off;
end;
TGarageDoor = class(TObject)
public
procedure Up;
procedure Down;
procedure Stop;
procedure LightOn;
procedure LightOff;
end; ......