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
Solved

Overriding TQuery.ExecSQL

Posted on 2014-02-14
6
434 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 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 26

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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