By default the focus is passed to the next control by pressing the Tab key. Well, sometimes (when filling out forms) you may want to pass to the next control after pressing Enter. Well, here’s the code: For TEdit controls only:
Select all the TEdit controls you want to include (using the Shift key), then select the Object Inspector, choose the Events tab and double click the OnKeyPress event. This way all the selected TEdit controls will use the same code. In the code editor write this code:
if Key = #13 then begin
Perform(WM_NEXTDLGCTL, 0, 0);
Key := #0; { Eat the key }
end;
For all the controls on the form:
This method will work for all controls because the form will take care of the event. All you have to do is set the form’s KeyPreview property to True and add this code to your form’s KeyUp event:
if (Key = VK_RETURN) and (Shift = []) then
Perform(WM_NEXTDLGCTL, 0, 0);
Categories: General Tags: borland, code, codegear, control, Delphi, double click, enter, faq, free, good, ide, key, key well, Kylix, next, object inspector, onkeypress event, return, shift key, source code, tab key, tedit, tip, trick, vk, wm, working
You shouldn’t have too much problem opening a Delphi 4 form in Delphi 2 but you won’t have luck opening a 32 bit or C++ Builder form in Delphi 1. The only way is to save the file in text form. Delphi 5 can do this automatically but in all the previous versions you have to do this all by yourself, form by form.
This is a full featured program that will do all the work for you. The source is dumped into Public Domain.
(* DfmToTxt 1.0
**
** Author: Jacob Dybala (m3Rlin). Public Domain
** <m3rlin@programmer.net>
**
** Created : January 2 2000
** Modified: April 12 2000
*)
program DfmToTxt;
{$apptype console} { Generate console application }
{$debuginfo off}
{$localsymbols off}
{$optimizations on}
{$rangechecks off}
uses
Classes, SysUtils;
var
sNewFileName: string;
strInput, strOutput: TStream;
begin
{ Initialize streams }
strInput := nil;
strOutput := nil;
{ Get commandline parameters }
if (ParamCount > 2) or (ParamCount = 0) then begin
WriteLn('DfmToTxt 1.0');
WriteLn('By Jacob Dybala (m3Rlin). Public Domain.');
WriteLn;
WriteLn('Usage: DfmToTxt <input /> <output></output>');
Exit;
end else if not FileExists(ParamStr(1)) then begin
WriteLn(Format('Error: %s can not be found.', [sNewFileName]));
Exit;
end if ExtractFileExt(ParamStr(1) <> '.dfm') then begin
WriteLn('Error: Input file must be a .dfm (Delphi Form) file');
Exit;
end;
if ParamCount = 1 then begin
sNewFileName := ParamStr(1);
sNewFileName := ChangeFileExt(sNewFileName, '.txt');
end else begin
sNewFileName := ParamStr(2);
if FileExists(sNewFileName) then begin
WriteLn(Format('Error: A file named %s already exists.', [sNewFileName]));
Exit;
end;
end;
{ Main code }
try
try
strInput := TFileStream.Create(ParamStr(1), fmOpenRead);
strOutput := TFileStream.Create(sNewFileName, fmCreate);
expect
Write('Error: Failed creating ');
WriteLn(sNewFileName);
Exit;
end;
ObjectResourceToText(strInput, strOutput);
finally
strInput.Free;
strOutput.Free;
end;
end;
Categories: General Tags: binary, borland, commandline parameters, convert, convertion, Delphi, delphi 1, delphi 2, delphi 4, delphi 5, dfm, faq, fileexists, form, format error, jacob dybala, Kylix, nil, old version, public domain, save as, text, tip, trick, window, write error