Solved

Overriding TQuery.ExecSQL

Posted on 2014-02-14
6
423 Views
Last Modified: 2014-02-18
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
Comment
Question by:csils
  • 3
  • 2
6 Comments
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 39858456
what your class definition as descendant of TQuery
and the procedures you want to override ?

in other words ... you have some code ?
0
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 39858463
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
 

Accepted Solution

by:
csils earned 0 total points
ID: 39858464
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 25

Expert Comment

by:Sinisa Vuk
ID: 39858848
Try not override but use overload keyword.
0
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 39858937
sinisa,
overload is when you have 2 procedures/functions with the same name
...
0
 

Author Closing Comment

by:csils
ID: 39866934
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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now