Ioannis Anifantakis
asked on
Override delphi events
Hello experts,
I want to find out how to override existing events in the following manner.
I have created a "manager object" for tables and datasets. The manager object does many similar things happening to all my connected tables and datasets.
Therefore I want to assign for example a "before post" that will be executed ON TOP of the before post I put in my table.
Short saying I want to have something like...
procedure TMyManagerClass.BeforePost (dataset: TDataSet); override;
begin
// do the things that I keep doing all the time
inherited; // <--do whatever extra functionality user defines on his normal "BeforePost" method
end;
procedure TMyManagerClass.DblClick(v iew: TcxGridTableView); override;
begin
// do the things that keep happening on the grid
inherited; //<-- if user defines extra funtionality on the dblclick, do it now
end;
To make it more simple, I want to do FIXED ADDITIONAL OPERATION to the one specified by the event the user can define, but do it through a manager class that contains a constructor that receives one dataset and one TcxTableView.
I want to find out how to override existing events in the following manner.
I have created a "manager object" for tables and datasets. The manager object does many similar things happening to all my connected tables and datasets.
Therefore I want to assign for example a "before post" that will be executed ON TOP of the before post I put in my table.
Short saying I want to have something like...
procedure TMyManagerClass.BeforePost
begin
// do the things that I keep doing all the time
inherited; // <--do whatever extra functionality user defines on his normal "BeforePost" method
end;
procedure TMyManagerClass.DblClick(v
begin
// do the things that keep happening on the grid
inherited; //<-- if user defines extra funtionality on the dblclick, do it now
end;
To make it more simple, I want to do FIXED ADDITIONAL OPERATION to the one specified by the event the user can define, but do it through a manager class that contains a constructor that receives one dataset and one TcxTableView.
What happens to your object if View is destroyed by its owner?
What if your object is destroyed?, Your dataset is suddenly pointing at events that don't exist anymore, what of the original events, they are all lost.
AV
ASKER
Dear ewangoya,
You are right on few things, and wrong on others.
Firstly, the code provides solution to the above problem without inheriting an object as my question dictates.
Secondly, exactly for the reasons you stated, incase of a foundamental change in dataset object that deprecates all the known events (which is impossible by the way), instead of changing all your code, you simply chane this unit's code and your system keeps running.
Finally, ofcourse you have to create the object manually, and free it manually at the "close" event of your form.
I provided this as it was my solution, so that people who might come to the same issue in the future know how to implement the "EXTRA" code for their events. In other words help the delphi community of the EE.
You are right on few things, and wrong on others.
Firstly, the code provides solution to the above problem without inheriting an object as my question dictates.
Secondly, exactly for the reasons you stated, incase of a foundamental change in dataset object that deprecates all the known events (which is impossible by the way), instead of changing all your code, you simply chane this unit's code and your system keeps running.
Finally, ofcourse you have to create the object manually, and free it manually at the "close" event of your form.
I provided this as it was my solution, so that people who might come to the same issue in the future know how to implement the "EXTRA" code for their events. In other words help the delphi community of the EE.
ASKER
also, if you believe you can enchant this to something better, please paste it here.
Thank you
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
o ... be aware of devexpress and editing
it works with listeners ...
you can't always stop editing in certain places, sometimes it's asynchronous using messages
it works with listeners ...
you can't always stop editing in certain places, sometimes it's asynchronous using messages
I did something similar in that I wanted to 'log' the opening and closing of the dataset so I assigned ALL of the different tables or queries to the same AfterOpen event.
Then inside that event you'll have to figure out what dataset component has called it;
I hope you get the 'jist' of this.
This becomes a *Central* AfterOpen event .
procedure TDataModuel1.ClientDataset AfterOpen( DataSet: TDataSet);
var s :string; t:TComponent;
begin
s := Dataset.Name;
try
t := FindComponent(s);
if Assigned(t) and
((TClientDataset(t).FileNa me <> '') or
(not TClientDataset(t).Connecti onBroker.C onnected)) then
if (TClientDataset(t).FileNam e <> '') then
s := s+' locally ('+TClientDataset(t).FileN ame+')'
else s := s+' running as disconnected dataset from ('+
TSocketConnection(TClientD ataset(t). Connection Broker.Con nection).H ost+')'
else s := s+' remotely ('+TSocketConnection(TClie ntDataset( t).Connect ionBroker. Connection ).Host+')' ;
except
on E:Exception do
begin
LogFile.LogMessageSt('Afte rOpen Exception: '+e.message,1);
s := Dataset.Name;
end;
end;
LogFile.LogMessageSt(s + ' opened.',3);
end;
Then inside that event you'll have to figure out what dataset component has called it;
I hope you get the 'jist' of this.
This becomes a *Central* AfterOpen event .
procedure TDataModuel1.ClientDataset
var s :string; t:TComponent;
begin
s := Dataset.Name;
try
t := FindComponent(s);
if Assigned(t) and
((TClientDataset(t).FileNa
(not TClientDataset(t).Connecti
if (TClientDataset(t).FileNam
s := s+' locally ('+TClientDataset(t).FileN
else s := s+' running as disconnected dataset from ('+
TSocketConnection(TClientD
else s := s+' remotely ('+TSocketConnection(TClie
except
on E:Exception do
begin
LogFile.LogMessageSt('Afte
s := Dataset.Name;
end;
end;
LogFile.LogMessageSt(s + ' opened.',3);
end;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
In the meantime, I made the unit that handles that myself and I paste it here for those who might be interested on such a functionality.
The class constructor takes DevExpress tableView or bandedView, and a dataset.
I provide a manager class for a grid/dataset combination. When browsing the grid, user doesn't have auto edit (OptionsBehavior.Immediate
It can take on the constructor either TableView or BandedView. so it works both for bands or tables.
Its an object that has to be manually created and takes (view, dataset) on the constructor. Its freed if you put a "free" call to the object at the "Close" of your form. You assign one such object for each tableview or bandedview you wish to manage.
On top of all that, you can easily get from the manager class whether the dataset is in edit or browsing mode by making a call to the "isEditing" function.
Enjoy
UcxGridDataSets.pas