Enter a string of text characters, pressing the Enter key or sorting the words in alphabetical order.
This is what I have, but when I press the Enter key nothing happens, that is when I press the enter key after typing the sentence it does not do what is needed it just makes a sound when pressed.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Label1: TLabel;
BitBtn1: TBitBtn;
ListBox1: TListBox;
Edit1: TEdit;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var s: TStringList;
begin
if Key = #13 then
begin
s:= TStringList.Create;
s.CommaText:= Edit1.Text;
s.Sort;
ListBox1.Items.Text:= s.Text;
s.Free;
end;
end;
end.
Many years without using it, good memories.
Instead of using the TKeyPressEvent you are using, you should use the
TKeyDownEvent( Sender: TObject, var key: word; shift: TShiftState );
According to the documentation,
TKeyPressEvent
it does not work for special and control keys, such as the keyENTER
.TKeyDownEvent
is the right one to use in those cases.you should declare two vectors taking the same length of the word, using one for the word, and the other to place them in order that, being Hexa values, will already recognize you by going through them with a loop which is greater and which is less, and a variable for use passing letters to the new array. I hope I have helped you with the logic. Cheers
I hope I have helped, regards