Topic: show form from scripts

how can I show a form from a script ?
I want to show a form (Form1) when pressing a key (for example "s" key) on keyboard!
Also I want to go to next field when press enter key on keyboard (Exactly like tab key).

Thanks a lot

Re: show form from scripts

Script:

procedure Form1_OnKeyDown (Sender: string; var Key: Word; Shift, Alt, Ctrl: boolean);
begin
     if key = 13 then Form1.SetFocusNextControl; // go to next field when press enter key on keyboard
end;

procedure Form1_OnKeyPress (Sender: string; var Key: Char);
begin
     if (Key = 's') or (Key='S') then Form2.ShowModal; // show Form2 when pressing a key "s" on keyboard!

end;

begin
     Form1.KeyPreview := True; // If KeyPreview is true, keyboard events occur on the form before they occur on the active control.
end.

Also you can download example project.

Post's attachments

Attachment icon Test.zip 2.55 kb, 641 downloads since 2014-10-12 

Dmitry.

Re: show form from scripts

Thanks a lot for answer smile

How can I use combination of keys in this Script ?

procedure Main_OnKeyPress (Sender: string; var Key: Char);
begin
   if (Key = 'a') or (Key='A') then addedittr.ShowModal;
   if (Key = 's') or (Key='S') then addeditcontact.ShowModal; 
   if (Key = 'p') or (Key='P') then Main.PageControl.ActivePage := Main.Personen; 
   if (Key = 't') or (Key='T') then Main.PageControl.ActivePage := Main.Transaktion; 
end;

For example "ctrl+a" ?!

Thanks a lot

Re: show form from scripts

for combination of keys you should use event OnKeyDown

procedure Form1_OnKeyDown (Sender: string; var Key: Word; Shift, Alt, Ctrl: boolean);
begin
     if (Chr(Key) = 'A') and (Ctrl) then ShowMessage('You press ctrl+a');
end;
Dmitry.

Re: show form from scripts

unfortunately code did not work sad

Re: show form from scripts

sonixax
Please, send me your project, i'll check it.
support@drive-software.com

Dmitry.

Re: show form from scripts

Hi,
Dear Dimitri
I sent project to you smile
Please check it if you have time smile
Thanks a lot

Re: show form from scripts

sonixax
unfortunately did not get, try send to drive.soft.mail@gmail.com

Dmitry.