New Page 1
(TMainMenu,
TEdit).
.
.
.
( ):
//
TESBAccount=class(TESBBaseClass)
protected
FCash:double;
FExceptionCash:boolean;
public
property Cash:double read FCash;
//
property ExceptionCash:boolean read
FExceptionCash write FExceptionCash;
constructor Create;
procedure Replenish(ACash:double);
//
procedure Withdraw(ACash:double);
//
procedure Serialize(AStream:TStream);
override;
procedure Unserialize(AStream:TStream);
override;
end; |
,
.
. ,
, :
constructor TESBAccount.Create;
begin
inherited Create;
FCash:=0;
FExceptionCash:=true;
end;
procedure TESBAccount.Replenish(ACash:double);
begin
FCash:=FCash+ACash;
end;
procedure TESBAccount.Withdraw(ACash:double);
begin
if FCash<ACash then
begin
if FExceptionCash then raise
Exception.Create(ClassName+': TESBAccount.Withdraw -
')
else FCash:=0;
end else FCash:=FCash-ACash;
end;
procedure TESBAccount.Serialize(AStream:TStream);
begin
inherited Serialize(AStream);
AStream.Write(FCash,sizeof(FCash));
AStream.Write(FExceptionCash,sizeof(FExceptionCash));
end;
procedure TESBAccount.Unserialize(AStream:TStream);
begin
inherited Unserialize(AStream);
AStream.Read(FCash,sizeof(FCash));
AStream.Read(FExceptionCash,sizeof(FExceptionCash));
end; |
. ,
, "Project"
-> "Add to project"*:

, ,
Delphi, ,
unit,
interface ,
TESBBaseClass TESBAccount*:

, ,
implementation*:

,
.
, .
(TMainMenu),
Standard*:

"" ""*

itSave itOpen *:

TMemo,
Standard*:

mmAccount.
(TEdit) - edSumma
(TButton) - btnAdd btnWithdraw -
.
, (TcheckBox)
- cbExceptionCash.
Standard.
dialogs
(TSaveDialog) (TOpenDialog)*:

*:

.
TfrmStockBot ( ) (
):
TfrmStockBot = class(TForm)
MainMenu: TMainMenu;
itFile: TMenuItem;
itSave: TMenuItem;
itOpen: TMenuItem;
mmAccount: TMemo;
edSumma: TEdit;
btnAdd: TButton;
btnWithdraw: TButton;
SaveDialog: TSaveDialog;
OpenDialog: TOpenDialog;
cbExceptionCash: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnAddClick(Sender: TObject);
procedure btnWithdrawClick(Sender: TObject);
procedure itSaveClick(Sender: TObject);
procedure itOpenClick(Sender: TObject);
procedure cbExceptionCashClick(Sender: TObject);
private
{ Private declarations }
Account:TESBAccount;
procedure ShowAccountCash;
public
{ Public declarations }
end; |
( ,
, ) :
procedure TfrmStockBot.FormCreate(Sender:
TObject);
begin
Account:=TESBAccount.Create;
cbExceptionCash.Checked:=Account.ExceptionCash;
end;
procedure TfrmStockBot.FormDestroy(Sender: TObject);
begin
FreeAndNil(Account);
end;
procedure TfrmStockBot.ShowAccountCash;
begin
mmAccount.Lines.Add(FloatToStr(Account.Cash));
end;
procedure TfrmStockBot.btnAddClick(Sender: TObject);
begin
Account.Replenish(StrToFloat(edSumma.Text));
ShowAccountCash;
end;
procedure TfrmStockBot.btnWithdrawClick(Sender: TObject);
begin
Account.Withdraw(StrToFloat(edSumma.Text));
ShowAccountCash;
end;
procedure TfrmStockBot.itSaveClick(Sender: TObject);
var Stream:TFileStream;
begin
if SaveDialog.Execute then
begin
Stream:=TFileStream.Create(SaveDialog.FileName,fmCreate);
Account.Serialize(Stream);
FreeAndNil(Stream);
end;
end;
procedure TfrmStockBot.itOpenClick(Sender: TObject);
var Stream:TFileStream;
begin
if OpenDialog.Execute then
begin
Stream:=TFileStream.Create(OpenDialog.FileName,fmOpenRead);
FreeAndNil(Account);
Account:=TESBAccount.Create;
Account.Unserialize(Stream);
FreeAndNil(Stream);
mmAccount.Lines.Clear;
ShowAccountCash;
end;
end;
procedure TfrmStockBot.cbExceptionCashClick(Sender: TObject);
begin
Account.ExceptionCash:=cbExceptionCash.Checked;
end; |
, uses
, *:

, ,
(Replenish - , Withdraw
, ,
)

.
, * ,
"Delphi",
"Borland Software Corporation".
|