Link to home
Start Free TrialLog in
Avatar of Ioannis Anifantakis
Ioannis AnifantakisFlag for Greece

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(view: 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.
Avatar of Ioannis Anifantakis
Ioannis Anifantakis
Flag of Greece image

ASKER

Ok, no solutions...

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.ImmediateEditor=false), but has auto-increment search (OptionsBehavior.IncSearch=true). When user starts editing, auto-edit comes and autoincrement leaves (the opposite). When inserting at either TableView or BandedView it moves the cursor to the leftmost cell for editing.

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
Avatar of Ephraim Wangoya

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
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.
also, if you believe you can enchant this to something better, please paste it here.
Thank you
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.ClientDatasetAfterOpen(DataSet: TDataSet);
var s :string; t:TComponent;
begin
  s := Dataset.Name;

  try
    t := FindComponent(s);
    if Assigned(t) and
       ((TClientDataset(t).FileName <> '') or
       (not TClientDataset(t).ConnectionBroker.Connected)) then
     if (TClientDataset(t).FileName <> '') then
     s := s+' locally ('+TClientDataset(t).FileName+')'
      else s := s+' running as disconnected dataset from ('+
          TSocketConnection(TClientDataset(t).ConnectionBroker.Connection).Host+')'
     else s := s+' remotely ('+TSocketConnection(TClientDataset(t).ConnectionBroker.Connection).Host+')';
  except
    on E:Exception do
    begin
      LogFile.LogMessageSt('AfterOpen Exception: '+e.message,1);
      s := Dataset.Name;
    end;
  end;
  LogFile.LogMessageSt(s + ' opened.',3);
end;
 
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial