Overriding TQuery.ExecSQL

In Delphi 7, I'm trying to override TQuery.ExecSql() and TQuery.Open() in order to add the query text to exception messages.

procedure ExecSql(); override;

I get a compiler error: 'Cannot override a static method', even though the procedure cannot be static

Without the 'override' keyword, the code compiles, but I get an access violation exception at the call to 'inherited'.

inherited ExecSql();

Any ideas?
csilsAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
csilsConnect With a Mentor Author Commented:
The exception reported by MadExcept (EAccessViolation) has turned out not to be the initial exception.  It was an EDatabaseException with a valid message (TableName property not set)

It somehow got converted to an EAccessViolation when re-raising
0
 
Geert GruwezOracle dbaCommented:
what your class definition as descendant of TQuery
and the procedures you want to override ?

in other words ... you have some code ?
0
 
Geert GruwezOracle dbaCommented:
TQuery has a static method for ExecSQL

so you need to use the magic trick to change it's behaviour

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, DBTables;

type
  TQuery = class(DBTables.TQuery)
  public
    procedure ExecSQL;
  end;

  TForm1 = class(TForm)
    Query1: TQuery;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
//
end;

{ TQuery }

procedure TQuery.ExecSQL;
begin
  try
    inherited ExecSQL;
  except
    on E: Exception do
      raise Exception.Create('Add something to the message : ' + E.Message);
  end;
end;

Open in new window

0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
Sinisa VukCommented:
Try not override but use overload keyword.
0
 
Geert GruwezOracle dbaCommented:
sinisa,
overload is when you have 2 procedures/functions with the same name
...
0
 
csilsAuthor Commented:
The reported exception was not the original one.  Therefore the actual problem was different, and correctly reported by the EDatabase error message: TableName property not set .
0
All Courses

From novice to tech pro — start learning today.