Ian Branch 127 Posted December 6, 2020 Hi Team, I need to prevent Users from actually editing, including deleting, a TComboBoxEx whilst still allowing the contents to be changed via the drop-down. The component's OnChange event fires whenever they do something in the field. The component doesn't have a Read-Only property. This might get in the road of the drop-down working, so what do I do? Regards & TIA, Ian Share this post Link to post
Guest Posted December 6, 2020 (edited) try this my sample: THIS WORKS BETTER! procedure TForm1.ComboBoxEx1KeyPress(Sender: TObject; var Key: Char); begin if not(Key = #0) then // if any char was typed by user! Key := #0; // imiting "Read-Only" effect! end; procedure TForm1.ComboBoxEx1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if not(Key = 0) then // to keys like DEL... Key := 0; end; Another Observations: when user use "CLICK Mouse", then, "OnClick" is raised for all changes, "OnBeginEdit" and "OnEndEdit" is raised any way then, you can use a "var" for to knows raise your changes, for example! another keys, like "DEL", "BackSpace" can fail in test (if not lWhoStartEditWasClick then or If Key='') - it's necessary more verification! some like this: (BUT IT FAILS IF THE VAR GOES TO = TRUE ALWAYS) - RE-EDITED var Form1: TForm1; implementation {$R *.dfm} var lWhoStartEditWasClick: boolean; // false procedure TForm1.ComboBoxEx1BeginEdit(Sender: TObject); begin Memo1.Lines.Add('beginedit ' + datetimetostr(now)); lWhoStartEditWasClick := false; end; procedure TForm1.ComboBoxEx1Change(Sender: TObject); begin Memo1.Lines.Add('Change ' + datetimetostr(now)); lWhoStartEditWasClick := false; // forcing new avaliation! end; procedure TForm1.ComboBoxEx1Click(Sender: TObject); begin Memo1.Lines.Add('Click ' + datetimetostr(now)); lWhoStartEditWasClick := true; end; procedure TForm1.ComboBoxEx1EndEdit(Sender: TObject); begin Memo1.Lines.Add('endedit ' + datetimetostr(now)); end; procedure TForm1.ComboBoxEx1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if not(Key = 0) then // keys as DEL Key := 0; end; procedure TForm1.ComboBoxEx1KeyPress(Sender: TObject; var Key: Char); begin //if not(Key = #0) then // chars if not lWhoStartEditWasClick then Key := #0; // end; end. hut Edited December 6, 2020 by Guest Share this post Link to post
Ian Branch 127 Posted December 6, 2020 Hi Emailx45, Oh, that is excellent! Thank you. I do like the added logging functionality. I am going to save that as a code snippet for the future. Regards, Ian Share this post Link to post
Ian Branch 127 Posted December 6, 2020 (edited) I did read them and they were noted. FYI - This is what I now have in place.. procedure TCustomersForm.IndexOrdKeyPress(Sender: TObject; var Key: Char); begin if not(Key = '') then // if any char was typed by user! begin MessageBeep(MB_ICONERROR); TaskMessageDlg('Editing not permitted!', 'You are not permitted to edit this entry. Please select from the drop-down options!', mtError, [mbOK], 0); IndexOrd.Text := 'Customer #'; Key := #0; // imiting "Read-Only" effect! end; end; Regards & Tks again, Ian Edited December 6, 2020 by Ian Branch Share this post Link to post
Guest Posted December 6, 2020 (edited) look again about the use of "key" as DEL, BackSpace ... try never use Dialogs on Events like this!!! you can have a effect non-desired and crash your apps Edited December 6, 2020 by Guest Share this post Link to post
Ian Branch 127 Posted December 6, 2020 I saw the observation about the DEL/Backspace, I am prepared to accept the risk att. OK. Noted on not using dialogs in this case. Unfortunate. I will revise. Share this post Link to post
Guest Posted December 6, 2020 for hints, use "Hint / ShowHits" properties Share this post Link to post
Ian Branch 127 Posted December 6, 2020 100% agree, but in this case the Customer's Users are not the quickest and unless something is in their face, it doesn't get much attention/credence. 😞 Share this post Link to post
Lajos Juhász 293 Posted December 7, 2020 I would just set the property Style to csExDropDownList. 1 Share this post Link to post
Guest Posted December 8, 2020 13 hours ago, Lajos Juhász said: I would just set the property Style to csExDropDownList. who dont read all options, dont see it!!! It's a shame by me! Sorry! ... uhhhhhh, shame on the moon!.... by Bob Seager! Share this post Link to post
Ian Branch 127 Posted December 8, 2020 No shame involved. I suspect ALL programmers are guilty of this more than once. ;-) Share this post Link to post