I have a form displaying data from a database, It has a few buttons and several panels. The panels contain a variety of components, specifically TEdits, TComboBox, TDateTimePicker, TCheckBox, TListBox and TstringGrid.
When the form is opened such that the user can view, but not edit, the data I currently disable all the components except for the buttons using
for i := 0 to FrmAddNewMember.ComponentCount-1 do
if FrmAddNewMember.Components[i] is TPanel then
(FrmAddNewMember.Components[ i ] as TPanel).enabled := false;
This works fine except that I would now like the user to be able to copy to the clipboard the text in the TEdits, the date in the TDateTimePicker, the selected item in the TComboBox etc etc. but still not change it.
I altered the code to the following which sets the TEdits to Read Only. This does what I want for TEdits but the other type of controls do not have a read only property, so I disabled them as before.
for i := 0 to FrmAddNewMember.ComponentCount-1 do
if not (FrmAddNewMember.Components[i] is TButton) then //(keep buttons working)
case FrmAddNewMember.Components[i] of
TEdit: (FrmAddNewMember.Components[ i ] as TEdit).readonly := true; //allows copying but not editing
TComboBox: (FrmAddNewMember.Components[ i ] as TComboBox).enabled := false; //no read only propert?
TDateTimePicker: (FrmAddNewMember.Components[ i ] as TDateTimePicker).enabled := false; //ditto
TCheckBox: (FrmAddNewMember.Components[ i ] as TCheckBox).enabled := false;
TListBox: (FrmAddNewMember.Components[ i ] as TListBox).enabled := false;
TstringGrid: (FrmAddNewMember.Components[ i ] as TstringGrid).enabled := false;
end;
Is there a way to make the other controls non editable but still allow their contents to be copied to the clipboard?
PS I have looked at
disable-edits-on-datagridview-but-still-allow-for-highlighting-to-copy-and-paste
and
make-all-controls-on-a-form-read-only-at-once-without-one-linkbutton
and searched elsewhere. Maybe it cannot be done simply.