![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Работа с записями [D7, XP]
allucard © (2007-12-04 10:08:00)Доброго утра всем.
Вопрос:
Есть запись (record) у которой есть поля:
type
TMagazin = record
kassa1: integer;
kassa2: integer;
kassa3: integer;
summa: integer;
end;
Как сделать так чтобы при добавлении (или вычитании) с одной из касс автоматически перещитывалась сумма?
(чтобы не перещитывать вручную)
т.е.
например:
kassa1=3;
kassa2=1;
kassa3=2;
summa=5;
kassa1 := kassa1+2;
а сумма сама пересчиталась и была равна 7.
p.s. знаю что на c++ visual studio есть возможность переопределения, как это сделать на дельфи?
Спасибо.
Думкин (2007-12-04 10:43:00) [21]> allucard (04.12.07 10:31) [2]
С помощью свойств. Причем на выбор:
TMagazin = class
private
kassa1: integer;
kassa2: integer;
kassa3: integer;
public
function summa: integer;
///Доступ к кассам и т.п
end;
function TMagazin.summa: integer;
begin
Result := kassa1 + kassa2 + kassa3
end;
Или так:
TMagazin = class
private
fkassa1: integer;
fkassa2: integer;
fkassa3: integer;
fsumma : integer;
procedure setkassa1(const Value: integer);
public
property kassa1 : integer read fkassa1 write setkassa1;
///Доступ к кассам и т.п
end;
procedure TMagazin.setkassa1(const Value: integer);
begin
fsumma := fsumma-fkassa1+Value;
fkassa1 := Value;
end;
Dennis I. Komarov (2007-12-04 10:43:00) [22]TAny=class(TComponent)
private
FKassa1: Integer;
FKassa2: Integer;
FKassa3: Integer;
FSumma: Integer;
procedure SetXML(const Value: TXMLDocument);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Kassa1: Integer read FKassa1 write SetKassa1;
property Kassa2: Integer read FKassa2 write SetKassa2;
property Kassa3: Integer read FKassa3 write SetKassa3;
property Summa: Integer read FSumma;
end;
....
procedure SetKassaX
begin
//Тут пересчет суммы
end;
Кажеться вот так
Писал в клиенте, если где что навалял - не бить :)
{RASkov} (2007-12-04 10:41:00) [23]> [0] allucard (04.12.07 10:08)
Сделать процедуры типа:
procedure AddInKassa(var m: TMagazin; const NK: Byte; const Value: Integer);
begin
with m do begin
case NK of
1: kassa1:=kassa1+Value;
......
end;
summa:=summa+Value;
end;
end;
где m - магазин, NK - номер кассы для операции, Value - значение.....
Вот в таком плане можно.... аналогично вычитание....если нужно)
Но если хочется "нормальной атоматизации", то лучше посмотреть в сторону классов и их методов...
> [2] allucard (04.12.07 10:31)
А немного подумать)
Dennis I. Komarov (2007-12-04 10:35:00) [24]> [2] allucard (04.12.07 10:31)
И.......
Это все?
Посмотри как пишутся классы
allucard (2007-12-04 10:31:00) [25]Ну, пусть в классе, только как?
type
TMagazin = class;
private
kassa1: integer;
kassa2: integer;
kassa3: integer;
summa: integer;
public
{ Public declarations }
end;
Думкин (2007-12-04 10:15:00) [26]В Д7 и не в классе - никак.