Okay, once again I find myself at the end of my rope after searching for a day and finding everything except the final piece of information I need.
I got a component called [blue]TNumEdit[/blue] that (go figure) accepts only numbers and is descended from TEdit.
[red]TNumEdit[/red]
It also has options for enabling or disabling whether negatives and decimals are allowed. It is really nice.
However, it doesn't have Copy or Paste enabled, since the C and V keys are on the ignore list.
I am trying to edit the component to enable just copying and pasting.
Here is the components [blue]OnKeyPress[/blue] event:
I have tried adding a small function to check the keyboard if Ctrl is clicked (also comes from [red]about.delphi.com[/red]):
So here is what I had added to the [blue]OnKeyPress[/blue] case statement:
The [blue]ShowMessage[/blue]'s are my temporary error trapping.
I find that in my program, the [blue]TNumEdit[/blue] will detect when v or c is pressed perfectly fine, unless holding the control button down when you hit it. If Ctrl is held down, it never gets into the [blue]OnKeyPress[/blue] event handler (Ctrl only counts for [blue]OnKeyDown[/blue], not [blue]OnKeyPress[/blue] I know, which is why I think this is happening).
Okay, added an [blue]OnKeyDown[/blue] (fires before [blue]OnKeyPress[/blue]) to just to try to handle if they are copying or pasting with keyboard shortcuts (Ctrl-C & Ctrl-V).
However, it won't build with that, and tells me there is an invalid type for the [blue]'v'[/blue] & [blue]'c'[/blue] (char vs word).
I am very very close, know where all the code goes either way. I just need somebody to help me either accept the [blue]'v'[/blue] & [blue]'c'[/blue] as what is pressed (have tried using [blue]#43[/blue] for c and such too there, no go) in the [blue]OnKeyDown[/blue] since they come in as word. OR if we could get it to register the C or V with [blue]OnKeyPress[/blue] since I yoinked that tiny function to check if Ctrl is pressed (that is assuming it works fine and dandy).
Anyone? =)
~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.
I got a component called [blue]TNumEdit[/blue] that (go figure) accepts only numbers and is descended from TEdit.
[red]TNumEdit[/red]
It also has options for enabling or disabling whether negatives and decimals are allowed. It is really nice.
However, it doesn't have Copy or Paste enabled, since the C and V keys are on the ignore list.
I am trying to edit the component to enable just copying and pasting.
Here is the components [blue]OnKeyPress[/blue] event:
Code:
procedure TNumEdit.WhenKeyPress(Sender: TObject; var Key: Char);
var
p : integer;
begin
case Key of
'0'..'9' : ;
'.',',' : if AllowDec AND
(pos(DecimalSeparator,Text)=0)
then Key:=DecimalSeparator
else Key:=#0;
#8 : ;
#45 : if FAllowNeg then
begin
p:=SelStart;
eValue:=-eValue;
if eValue>0
then SelStart:=p-1
else SelStart:=p+1;
Key:=#0;
end;
else Key:=#0;
end;
end;
I have tried adding a small function to check the keyboard if Ctrl is clicked (also comes from [red]about.delphi.com[/red]):
Code:
function TNumEdit.CtrlDown : Boolean;
var
State : TKeyboardState;
begin
GetKeyboardState(State) ;
Result := ((State[vk_Control] And 128) <> 0) ;
end;
Code:
'v' : begin
ShowMessage ('v is pressed');
if (CtrlDown = True) then
begin
ShowMessage ('Ctrl is pressed');
PasteFromClipboard
end
else
begin
ShowMessage ('Ctrl is NOT pressed');
Key:=#0;
end;
end;
'c' : if (CtrlDown = True) then
CopyToClipboard
else
Key:=#0;
I find that in my program, the [blue]TNumEdit[/blue] will detect when v or c is pressed perfectly fine, unless holding the control button down when you hit it. If Ctrl is held down, it never gets into the [blue]OnKeyPress[/blue] event handler (Ctrl only counts for [blue]OnKeyDown[/blue], not [blue]OnKeyPress[/blue] I know, which is why I think this is happening).
Okay, added an [blue]OnKeyDown[/blue] (fires before [blue]OnKeyPress[/blue]) to just to try to handle if they are copying or pasting with keyboard shortcuts (Ctrl-C & Ctrl-V).
Code:
procedure TNumEdit.WhenKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
'v' : if (ssCtrl in Shift) then
PasteFromClipboard
else
Key:=#0;
'c' : if (ssCtrl in Shift) then
CopyToClipboard
else
Key:=#0;
end;
end;
I am very very close, know where all the code goes either way. I just need somebody to help me either accept the [blue]'v'[/blue] & [blue]'c'[/blue] as what is pressed (have tried using [blue]#43[/blue] for c and such too there, no go) in the [blue]OnKeyDown[/blue] since they come in as word. OR if we could get it to register the C or V with [blue]OnKeyPress[/blue] since I yoinked that tiny function to check if Ctrl is pressed (that is assuming it works fine and dandy).
Anyone? =)
~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.