Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Delphi / Winboard

Author: Andrew Dados

Date: 09:42:02 07/13/00

Go up one level in this thread


On July 13, 2000 at 10:54:58, Tony Werten wrote:

>Hello all,
>
>I finally managed to send messages from my delphi app to Winboard. Before I'm
>going to spend another week on finding out how to read messages from winboard, I
>just want to check.
>
>Did somebody already do this ?
>
>Tony

You may try doing this in 2 ways:


1. non-blocking polling pipe, ala Crafty.

function isinput:boolean;
var
inh:THandle;
dw:dword;
numtoread:dword;
begin
dw:=0;
 inh := GetStdHandle(STD_INPUT_HANDLE);
   if (not PeekNamedPipe(inh, Nil, 0, Nil, @numtoread, Nil)) then numtoread:=0;
isinput:=numtoread>0;
end;

-------------------------------------
2. Separate dedicated thread which will be blocked on waiting for input all the
time, so it uses no processor time (I do it this way):

var Sin:  String; {global input string}

function DoInput(Ap:Pointer): Integer;
var S:string;
    ch:char;
begin
repeat
S:='';
repeat
Read(Input,ch); {blocking read}
S:=S+ch;
until ch=#10;
Sin:=S;
Dispatch; {this procedure examines input and decides what to do}
until Sin='quit'+#10;
EndThread(0);
end;

procedure StartReading;
{called once in beginning of program to start the reading thread}
var
  Flags: Integer;
  FInputHandle:THandle;
begin
doneThread:=False; Flags := 0; FInputHandle :=BeginThread(nil, 0, @DoInput, nil,
Flags, Flags);
end;

I hope it helps...
-Andrew-










This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.