String handling in Buffer
The TIdTelnet component has an event handler called OnDataAvailable which handles all the messages sent by the host
The function is like this
//----------------------
void __fastcall TForm1::IdTelnet1DataAvailable(AnsiString Buffer)
{
}
//----------------------
Here Buffer is where all the messages are recieved
The Default Message i should get when i log on to the host is as below
-------------------
PCQLinux 2004 (NewDawn)
Kernel 2.4.22-1.2115.nptl on an i686
login:
-------------------
So my function should be something like this
//----------------------
void __fastcall TForm1::IdTelnet1DataAvailable(AnsiString Buffer)
{
AnsiString s;
s=Buffer;
if(s=="login: ")
{
IdTelnet1->WriteLn("postgres");
}
}
//----------------------
Here i'm waiting for the "login: " or in any case the last line to appear in buffer after which the function is called.
But the condition fails because when i check the value of "s" it will be some thing like this
"PCQLinux 2004 (NewDawn)\r\nKernel 2.4.22-1.2115.nptl on an i686\r\nlogin: "
So i did something like this but That to did not help
//----------------------
void __fastcall TForm1::IdTelnet1DataAvailable(AnsiString Buffer)
{
int Start, Stop;
Start = 1;
Stop = Buffer.Pos(IntToStr('\n')); //the character count to a CR in the buffer
if(Stop == 0)
Stop = Buffer.Length() + 1;
while(Start <= Buffer.Length())
{
s=Buffer.SubString(Start,Stop-Start);
if(Buffer.SubString(Stop,1)=='\n')
{
}
Start = Stop + 1;
if(Start > Buffer.Length())
{
break;
}
if(Buffer.SubString(Start,1)=='\n')
{
Start++;
}
Stop = Start;
while((Buffer.SubString(Stop, 1)!= '\n')&&(Stop <= Buffer.Length()))
{
Stop++;
}
}
value->Text=s;
if(s=="login: ")
{
IdTelnet1->WriteLn("postgres");
}
}
//----------------------
But still the problem repeats.Any help is greatly appreciated. Thanks in advance.

