Solved

Overriding TQuery.ExecSQL

Posted on 2014-02-14
6
444 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 37

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 37

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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