Delphi TClientDataSet - override Refresh event

Hy

I Created a component derivated from TClientDataSet.

I'm having trouble to override the refresh event.
I need to "kill" the active event, and make I new one.

So, when the user is on the DBNavigator, and triggers the "Refresh" option, it should call the new method.

Here is the code for the component that I have today.
Could you help me to achieve this result?

Thanks.

unit ERPDataSet;

interface

uses
  System.SysUtils, System.Classes, Data.DB, Datasnap.DBClient;

type
  TERPDataSet = class(TClientDataSet)
  private
    { Private declarations }
    FNomeTabela: string;
    FChavePrimaria: string;
    FComandoSQL:string;
  protected
    { Protected declarations }
  public
    { Public declarations }
    procedure IncluiChavePrimaria;
  published
    { Published declarations }
    property ChavePrimaria:string read FChavePrimaria write FChavePrimaria;
    property ComandoSQL:string read FComandoSQL write FComandoSQL;
    property NomeTabela:string read FNomeTabela write FNomeTabela;
  end;

procedure Register;

implementation

//=================================================================================================================================================================================
procedure Register;
begin
  RegisterComponents('Rafael', [TERPDataSet]);
end;

{ TERPDataSet }

//=================================================================================================================================================================================
procedure TERPDataSet.IncluiChavePrimaria;
begin
  IndexDefs.Add('idx' + Name,ChavePrimaria,[ixPrimary,ixUnique]);
  IndexName:= 'idx' + Name;
  First;
end;

end.

Open in new window

rafaelrascheAsked:
Who is Participating?
 
Sinisa VukCommented:
Override InternalRefresh method of your new clientdataset:

TERPDataSet = class(TClientDataSet)
  private
..
  protected
...
  procedure InternalRefresh; override;
...
end;
....

procedure TERPDataSet.InternalRefresh;
begin
  if then ....
  else inherited InternalRefresh
end;

Open in new window

0
 
Eddie ShipmanAll-around developerCommented:
Override and don't call inherited. That's all there is to it.
0
 
atul_parmarCommented:
>>So, when the user is on the DBNavigator, and triggers the "Refresh" option, it should call the new method.

In this case you will need to write your DBNavigator that calls your method.
0
 
rafaelrascheAuthor Commented:
Thanks man!
That really did what I needed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.