• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 509
  • Last Modified:

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?
0
csils
Asked:
csils
  • 3
  • 2
1 Solution
 
Geert GOracle 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 GOracle 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
 
csilsAuthor 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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Sinisa VukCommented:
Try not override but use overload keyword.
0
 
Geert GOracle 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
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.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now