tags:

views:

121

answers:

3

To avoid entering single quotes. But got error while compiling the project - '[Fatal Error] StdCtrls.pas(1238): Unit Dialogs was compiled with a different version of StdCtrls.TEdit'

+2  A: 

The source code for the VCL is available to read and to debug but the license does not allow you to make changes and distribute those changes (at least as far as I know).

In your case it would be better to make a new control that descends from TEdit (or TCustomEdit) if you want to reuse this control in multiple forms or projects.

Otherside
Hi... Thanks for the response. I was able modified KeyPress method (was already overriden) in TDBEdit class, in DBCntrls unit and it compiled without any error. But in case of TEdit I did the following change TEdit = class(TCustomEdit) //Melvina protected procedure KeyPress(var Key: Char); override; //Melvina Do you find any catch in this approach? We have used TEdit manytimes across the project. Deriving new control and replacing would involve great effort for development and testing. Please let me know if any suggestions. Thanks in advance....Melvina
melvina
What you're not allowed to distribute is a new version of any of the Delphi-provided *packages*. You can recompile the Delphi-provided units as long as they're contained by your EXE or one of *your own* packages.
Rob Kennedy
@melvina - > "Deriving new control and replacing would involve great effort" - If adding a unit reference to the uses clause whereever you need the overridden behavior is feasable, then take a look at **interposer** classes (http://blog.marcocantu.com/blog/handbook_note_67.html).
Sertac Akyuz
@Rob Kennedy: I knew there was some restriction, but I wasn't quite sure what exactly. Thanks for making that clear.
Otherside
thanks for your responses...
melvina
+3  A: 

Simply write an OnKeyPress event handler:

procedure TMyForm.EditNoSingleQuotes(Sender: TObject; var Key: Char);
begin
  if Key = '''' then Key := #0;
end;

Or inherit from TEdit and override the KeyPress method:

procedure TMyEdit.KeyPress(var Key: Char);
begin
  if Key = '''' then Key := #0;
  inherited KeyPress(Key);
end;
splash
Good solution for one or two forms, bad solution for 100 forms.
Chris Thornton
@Chris: understood! ;-)
splash
+7  A: 

You changed the interface of the StdCtrls unit. That requires all units that use it to be recompiled as well, even the Delphi-provided VCL units. If there's ever a way to accomplish a goal without modifying Delphi's units, prefer it.

There's no need to provide your own version of StdCtrls.pas. Everything you need to do can be done by inheriting from the basic TEdit control. Years ago, Peter Below demonstrated how to filter the input of an edit control to accept only numbers. You can adapt that code to accept everything except apostrophes.

In short, you do this:

Rob Kennedy
Well answered! +1
splash
Even included the often overlooked paste handling. I am wodering why melvina wants to exclude quotes though - I suspect there may be an attempt to prevent quotes in a generated sql, in which case a parameterised query (or at least QuotedStr) may be a better solution.
Gerry
melvina