Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Delphi / Winboard

Author: Andrew Dados

Date: 11:07:15 07/14/00

Go up one level in this thread


On July 14, 2000 at 10:13:22, Tony Werten wrote:

>On July 13, 2000 at 12:42:02, Andrew Dados wrote:
>
>>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;
>
>Couldn't get this working.

Hmm... try:

while isinput do
 begin
 readln(S); {or read one char at a time till u get #10 and construct a string}
 DoSomethingWithIt;
 end;

I use isinput now to distinguish winboard from starting my program in standalone
mode (winboard stuffs pipe with 'winboard' string upon startup):

if isinput then {winboard mode} else {standalone}
>
>>
>>-------------------------------------
>>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;
>
>That was basicly what I was thinking of. But I didn't expect it to work, so I
>stopped to start again today. But it did work immediately.
>Now I have to write the parser shit.
>
>Why does the winboard manual say you have to make a console app ?

You don't have to, however winboard allocates console for you along with pipes,
so your program gets a console anyway. It can be a gui app and still use a
console.... (Bringer does it).

>
>>
>>I hope it helps...
>
>It did, thanks.
>
>Tony
>>-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.