Программирование - это просто
Advertisement
arrow arrow , , arrow Delphi. 15. (TMainMenu, TEdit).
01.02.2023 .
1:
C#
Delphi
Web-
Excel-
.
Delphi. 15. (TMainMenu, TEdit). E-mail
megabax   
04.03.2010 .
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"*:

    (TMainMenu, TEdit).

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

, , implementation*:

    , .

, . (TMainMenu), Standard*:

TMainMenu, TEdit

"" ""*

TMainMenu, TEdit

itSave itOpen *:

TMainMenu, TEdit

TMemo, Standard*:

TMainMenu, TEdit

mmAccount.

(TEdit) - edSumma (TButton) - btnAdd btnWithdraw - .

, (TcheckBox) - cbExceptionCash. Standard.

dialogs (TSaveDialog) (TOpenDialog)*:

TMainMenu, TEdit,

*:

TMainMenu, TEdit,

. 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 , *:

 http://easyprog.ru/index.php?option=com_content&task=view&id=235&Itemid=29

, , (Replenish - ,  Withdraw , , )

TMainMenu, TEdit,  ,

.


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

 

( 17.07.2013 . )
 
« .   . »
 
© 2023 Программирование - это просто
Joomla! - , GNU/GPL.
© 2005-2008 Joom.Ru - Joomla!
Design by Mamboteam.com | Powered by Mambobanner.de
  .