Jump to content

How to block editing UniDateTimePicker from the keyboard?


Lena
 Share

Recommended Posts

static void fixDateTimePicker(TUniCustomDateTimePicker * dt)
{
	TUniDateTimePicker * dtp = dynamic_cast<TUniDateTimePicker*>(dt);
	TUniDBDateTimePicker * dbdtp = dynamic_cast<TUniDBDateTimePicker*>(dt);
	TUniDateTimeKind kind;
	if (dtp != NULL)
		kind = dtp->Kind;
	else if (dbdtp != NULL)
		kind = dbdtp->Kind;
	else
		return;
	
        UnicodeString ev = L" function(sender) { sender.editable = false; }";

	if (kind == tUniDate || kind == tUniTime)
	{
		if (dtp != NULL)
			dtp->ClientEvents->ExtEvents->Values[L"afterrender"] = ev;
		else if (dbdtp != NULL)
			dbdtp->ClientEvents->ExtEvents->Values[L"afterrender"] = ev;
	}
	else
	{
		if (dtp != NULL)
		{
			dtp->ClientEvents->ExtEvents->Values[L"date.afterrender"] = ev;
			dtp->ClientEvents->ExtEvents->Values[L"time.afterrender"] = ev;
		}
		else if (dbdtp != NULL)
		{
			dbdtp->ClientEvents->ExtEvents->Values[L"date.afterrender"] = ev;
			dbdtp->ClientEvents->ExtEvents->Values[L"time.afterrender"] = ev;
		}
	}
}

this works for both DB and non-DB components.

Link to comment
Share on other sites

Please, port source code to Delphi.

:D

 

Come on! Is non THAT hard! :)

 

For starters, here is a quick and dirty port (I am not even sure that compiles). If you can improve it please reply with your solution.

procedure fixDateTimePicker(dt:TUniCustomDateTimePicker)
var
	dtp:   TUniDateTimePicker;
	dbdtp: TUniDBDateTimePicker;
	kind: TUniDateTimeKind;
	ev: string;
begin
	dtp := nil;
	dbdtp := nil;
	
	if dt is TUniDateTimePicker then
	begin
		dtp := dt as TUniDateTimePicker;
		kind := dtp.Kind;
	end
	elsif dt is TUniDBDateTimePicker then
	begin
		dbdtp := dt as TUniDBDateTimePicker;
		kind := dbdtp.Kind;
	end
	else
		Exit;
	
        ev := ' function(sender) { sender.editable = false; }';

	if (kind = tUniDate) or (kind = tUniTime) then 
	begin
		if (dtp <> nil) then
			dtp.ClientEvents.ExtEvents.Values['afterrender'] := ev
		elsif (dbdtp <> nil) then
			dbdtp.ClientEvents.ExtEvents.Values['afterrender'] := ev;
	end
	else
	begin
		if (dtp <> nil) then
		begin
			dtp.ClientEvents.ExtEvents.Values['date.afterrender'] := ev;
			dbdtp.ClientEvents.ExtEvents.Values['time.afterrender'] := ev;
		end
		elsif (dbdtp <> nil) then
		begin
			dtp.ClientEvents.ExtEvents.Values['date.afterrender'] := ev;
			dbdtp.ClientEvents.ExtEvents.Values['time.afterrender'] := ev;
		end;
	end;
end;
  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...