Soloway's recurring rainfall: Difference between revisions
m
→{{header|Delphi}}
No edit summary |
|||
Line 399:
To get the TMemo to behave like a console application, I've created an object that captures keyboard into to the TMemo and can return the keystrokes a chars, integers or reals. The object, which is called "TKeyWaiter," is simply created and attached to a TMemo component. While the object is alive, it will capture key stroke and return chars, integers or reals. It can be destroyed as soon as it is no longer needed. In fact, in this code, I create and destroy it for every input. The creation overhead is so low that there is no reason to create a global copy and keep it alive while the program is operating.
<syntaxhighlight lang="Delphi">
{TKeywaiter interface}
type TKeyWaiter = class(TObject)
private
FControl: TWinControl;
FControlCAbort: boolean;
protected
procedure HandleKeyPress(Sender: TObject; var Key: Char);
public
KeyChar: Char;
ValidKey: boolean;
AbortWait: boolean;
constructor Create(Control: TWinControl);
function WaitForKey: char;
function WaitForInteger: integer;
function WaitForReal: double;
property ControlCAbort: boolean read FControlCAbort write FControlCAbort;
end;
{ TMemoWaiter implementation }
type TControlHack = class(TWinControl) end;
Line 661 ⟶ 587:
</pre>
=={{header|Fortran}}==
|