Reputation: 113
Good day, so I was wondering if it would be possible to do something like this:
On Startup TEdit(Edit1) is disabled - so Edit1.enabled := false;
When the user clicks on the TEdit it would be enabled and it would do other stuff, I have tried with the Edit1.onClick but it doesn't seem to work, since it's disabled.
Upvotes: 1
Views: 812
Reputation: 54772
A disabled control passes through clicks to the window beneath it. IOW, you can look for clicks on the parent of the disabled edit provided the parent is enabled; acquire the position of the click and query if it's on a control.
Below is an example detecting a click on a disabled edit placed on a form. You would need to adjust accordingly if the edits are parented by another container, such as a panel.
procedure TForm1.FormClick(Sender: TObject);
var
Pt: TPoint;
Wnd: HWND;
Control: TControl;
begin
Pt := ScreenToClient(SmallPointToPoint(types.SmallPoint(GetMessagePos)));
Wnd := ChildWindowFromPoint(Handle, Pt);
if Handle <> Wnd then begin
Control := FindControl(Wnd);
if (Control is TEdit) and not Control.Enabled then
Control.Enabled := True;
end;
end;
Upvotes: 1