{Dialog 单元}
unit Unit1;
interface
uses
Forms, Classes, Controls, StdCtrls;
type
TForm1 = class(TForm)
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
end.
{Console Application}
program Test;
{$APPTYPE CONSOLE}
uses
Windows,
Messages,
Forms,
Unit1 in 'Unit1.pas' {Form1};
var
hInput : THandle;
inRec : TInputRecord;
dwCount : DWORD;
begin
{Create a Form in the usual way. The Forms unit ensures that
the Application object is around to "own" the form.}
Write('Creating the first Dialog Box...');
Form1 := TForm1.Create(Application);
Form1.Show;
Writeln('done.');
Writeln('Press 1, 2 or 3 to change the dialog box. Press Ctrl+ C to exit');
{Handle the Console input till the user cancels}
hInput := GetStdHandle(STD_INPUT_HANDLE);
{GetStdHandle - Returns handle for Standard input/output device}
while True do begin
{Avoid blocking on user input, so the forms have a chance
to operate as normal. If we had a message queue present, this
would be a normal message dispatch loop.}
Application.ProcessMessages;
if WaitForSingleObject(hInput,0) = WAIT_OBJECT_0 then begin
ReadConsoleInput(hInput, inRec, 1, dwCount);
if (inRec.EventType = KEY_EVENT) and inRec.Event.KeyEvent.bKeyDown then begin
case inRec.Event.KeyEvent.AsciiChar of
'1' : begin
Writeln('->1');
Form1.RadioButton1.Checked := True;
end;
'2' : begin
Writeln('->2');
Form1.RadioButton2.Checked := True;
end;
'3' : begin
Writeln('->3');
Form1.RadioButton3.Checked := True;
end;
end;
end;
end;
end;
end.
From www.delphi3000.com
function StringIndex(const SearchString: string; StrList: array of string): Integer;
var
I: Integer;
begin
Result:= -1;
for I:= 0 to High(StrList) do
if CompareText(SearchString, StrList[I]) = 0 then
begin
Result:= I;
Break;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
case StringIndex('A', ['A', 'B', 'C']) of
-1: ShowMessage('Not in the list');
0: ShowMessage('A');
1: ShowMessage('B');
2: ShowMessage('C');
end;
end;
From www.delphi3000.com