Forum > Windows
[solved] need help for TEDIT component
compispezi@web.de:
Hello, I am learning about Lazarus. I want to catch key up and key down and enter in TEDIT fields to jump to other TEDIT fields.
In the example I have written this for TEDIT2. But, as soon as I go into TEDIT2 and press a key, the programme stops and can only be terminated with CTRL+F2. Can you please give me support?
Here is the example:
unit unit1;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm2 }
TForm2 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure Edit2KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
private
public
end;
var
Form2: TForm2;
implementation
{$R *.lfm}
{ TForm2 }
procedure TForm2.Edit2KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
begin
case key of
38 : Edit1.SetFocus; //hoch
40,13 : Edit3.SetFocus //runter, Enter
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
Form2.Close;
end;
end.
Gald:
I've tried some things and found out strange behavior.
You have to declare LCLType to the uses and then Uses session this code:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if key = VK_DOWN then SelectNext(Self as TWinControl, True, False);
A common way to do it is setting the property KeyPreview of your TForm as True.
But... Arrow keys are used by the system to move the keyboard cursor around the TEdit. That's why I've tried on the TEdit's key events, but for my surprise, SelectNext it's going back to the first control (TabStop = 0) every time I press the arrow down.
So, now I'm confusing:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---//This is setting focus to the first control (TabStop = 0)SelectNext(Self as TWinControl, False, False); //This is setting focus on the last controlSelectNext(Self as TWinControl, False, False);
Sounds like a bug to me!
HeavyUser:
Well, which control you think self is?
Try using the parameter sender instead.
Gald:
--- Quote from: HeavyUser on August 06, 2022, 09:56:54 pm ---Well, which control you think self is?
Try using the parameter sender instead.
--- End quote ---
Same results.
HeavyUser:
--- Quote from: Gald on August 06, 2022, 10:21:32 pm ---
--- Quote from: HeavyUser on August 06, 2022, 09:56:54 pm ---Well, which control you think self is?
Try using the parameter sender instead.
--- End quote ---
Same results.
--- End quote ---
attach a small sample that demonstrates the bug please.
Navigation
[0] Message Index
[#] Next page