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'
views:
121answers:
3The 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.
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;
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:
- Override
KeyPress
to reject unwanted keys. Splash's answer demonstrates that. - Provide a
wm_Paste
message handler to filter unwanted characters from the clipboard. - Provide
wm_SetText
andem_ReplaceSel
message handlers to filter unwanted characters arising from direct use of theText
andSelText
properties.