Thread View: borland.public.cppbuilder.internet.socket
7 messages
7 total messages
Started by Roger Hemme
Thu, 14 Dec 2006 22:25
Tranlation problem
Author: Roger Hemme
Date: Thu, 14 Dec 2006 22:25
Date: Thu, 14 Dec 2006 22:25
56 lines
2699 bytes
2699 bytes
This is a piece of code posted by Mr. Lebeau in the discussion "Adding
news messages to a tree" (2004). I have some problems translating this
into Delphi-code. (I'm not very familiar with C++)
Espesially the: " if(node) " - part.
If(node) /what/?
(PS - I don't need help with the FindParentMessage-function earlier i
that thread)
TStringList *Messages = new TStringList;
try
{
TStringList *XOverData = new TStringList;
try
{
int ArticleIndex, ByteCount, LineCount;
AnsiString Subject, From, MsgId, References, ExtraData;
TDateTime dtDate;
TTreeNode *Node;
// use whatever article indexes you are actually downloading
IdNNTP1->XOVER(AnsiString(IdNNTP1->MsgLow) + "-" +
AnsiString(IdNNTP1->MsgHigh), XOverData);
TreeView1->Items->BeginUpdate();
try
{
for(int x = 0; x < XOverData->Count; ++x)
{
IdNNTP1->ParseXOVER(XOverData->Strings[x],ArticleIndex,
Subject, From, dtDate, MsgId, References, ByteCount, LineCount,
ExtraData);
Node = FindParentMessage(Messages, References);
if( Node )
Node = TreeView1->Items->AddChild(Node,Subject);
else
Node = TreeView1->Items->Add(NULL, Subject);
}
Messages->AddObject(MsgId, Node);
}
}
__finally {
TreeView1->Items->EndUpdate();
}
}
__finally {
delete XOverData;
}
}
__finally {
delete Messages;
}
Thanks in advance!
Re: Tranlation problem
Author: Remy Lebeau (TeamB)
Date: Thu, 14 Dec 2006 22:54
Date: Thu, 14 Dec 2006 22:54
52 lines
2658 bytes
2658 bytes
"Roger Hemme" <rog@net.nl> wrote in message
news:4581cf08@newsgroups.borland.com...
> This is a piece of code posted by Mr. Lebeau in the discussion "Adding
> news messages to a tree" (2004). I have some problems translating this
> into Delphi-code.
var
Messages: TStringList;
XOverData: TStringList;
ArticleIndex, ByteCount, LineCount, I: Integer;
Subject, From, MsgId, References, ExtraData: String;
dtDate: TDateTime;
Node: TTreeNode;
begin
Messages := TStringList.Create;
try
XOverData := TStringList.Create;
try
// use whatever article indexes you are actually downloading
IdNNTP1.XOVER(IntToStr(IdNNTP1->MsgLow) + '-' +
IntToStr(IdNNTP1.MsgHigh), XOverData);
TreeView1.Items.BeginUpdate;
try
for I := 0 to XOverData.Count-1 do
begin
IdNNTP1.ParseXOVER(XOverData[I], ArticleIndex,
Subject, From, dtDate, MsgId, References, ByteCount, LineCount, ExtraData);
Node := FindParentMessage(Messages, References);
if Assigned(Node) then
Node := TreeView1.Items.AddChild(Node, Subject)
else
Node := TreeView1.Items.Add(nil, Subject);
Messages.AddObject(MsgId, Node);
end;
finally
TreeView1.Items.EndUpdate;
end;
finally
XOverData.Free;
end;
finally
Messages.Free;
end;
end;
Gambit
Re: Tranlation problem
Author: Roger Hemme
Date: Thu, 14 Dec 2006 23:28
Date: Thu, 14 Dec 2006 23:28
57 lines
2856 bytes
2856 bytes
Remy Lebeau (TeamB) skrev:
> "Roger Hemme" <rog@net.nl> wrote in message
> news:4581cf08@newsgroups.borland.com...
>
>
> var
> Messages: TStringList;
> XOverData: TStringList;
> ArticleIndex, ByteCount, LineCount, I: Integer;
> Subject, From, MsgId, References, ExtraData: String;
> dtDate: TDateTime;
> Node: TTreeNode;
> begin......
Thank you very much, Gambit! But...what i'm trying to do isn't working,
so i wonder if the translation i have of the " FindParentMessage " -
function is wrong? Here it is:
function FindParentMessage(Messages: TStrings; References: String):
TTreeNode;
var pFirst: PChar;
pStop: PChar;
pStart: PChar;
pEnd: PChar;
MsgIdToFind: String;
idx: Integer;
begin
result:=nil;
if not(Length(References) = 0) or (Messages = nil) then
begin
pFirst:=PChar(References);
pStop:=pFirst + 2;
pStart:=AnsiLastChar(References);
pEnd:=pStart;
while (pEnd > pStop) do
begin
while ((pEnd > pStop) and (pEnd^ <> '>')) do Dec(pEnd);
if (pEnd = pStop) then break;
pStart:=(pEnd - 1);
while ((pStart >= pFirst) and (pStart <> '<')) do Dec(pStart);
if (pStart < pFirst ) then break;
SetString(MsgIdToFind, pStart, pEnd - pStart + 1);
for idx:=Pred(Messages.Count) downto 0 do
begin
if (Messages[idx] = MsgIdToFind) then
begin
result:=TTreeNode(Messages.Objects[idx]);
exit;
end;
end;
pEnd:=(pStart - 1);
end;
end;
end;
Re: Tranlation problem
Author: Remy Lebeau (TeamB)
Date: Fri, 15 Dec 2006 02:50
Date: Fri, 15 Dec 2006 02:50
17 lines
1520 bytes
1520 bytes
"Roger Hemme" <rog@net.nl> wrote in message news:4581DE1B.7050909@net.nl... > what i'm trying to do isn't working What exactly are you trying to do? What exactly is not working for you? Please be more specific. > i wonder if the translation i have of the " FindParentMessage " > function is wrong? You did not show the original C++ code that you are trying to translate, and it is not in the newsgroup archives. I cannot tell you if the translation is accurate or not. Gambit
Re: Tranlation problem
Author: Roger Hemme
Date: Fri, 15 Dec 2006 06:13
Date: Fri, 15 Dec 2006 06:13
113 lines
4740 bytes
4740 bytes
Remy Lebeau (TeamB) skrev:
> What exactly are you trying to do? What exactly is not working for you?
> Please be more specific.
> You did not show the original C++ code that you are trying to translate, and
> it is not in the newsgroup archives. I cannot tell you if the translation
> is accurate or not.
>
>
You're right. I should have been more spesific.Sorry about that.
I'm trying download newsgroup articles in a threaded layout.
I found the discussion here:
http://216.101.185.148/scripts/isapi.dll/thread?id=5D6C5471&thread=1267947
The BCB-code:
TTreeNode* __fastcall FindParentMessage(TStrings *Messages, AnsiString
References)
{
if( !References.IsEmpty() )
{
char *pFirst = References.c_str();
char *pStop = (pFirst+2);
char *pStart, *pEnd = References.AnsiLastChar();
// scan through the reference list from back to front as
// newer messages in a discussion are at the end of the list
while( pEnd > pStop )
{
// find the end of the MsgID
while( (pEnd > pStop) && (*pEnd != '>') ) --pEnd;
if( pEnd == pStop ) break;
// find the start of the MsgID
pStart = (pEnd-1);
while( (pStart >= pFirst) && (*pStart != '<') ) --pStart;
if( pStart < pFirst ) break;
// find the MsgID in the stored list. chances are, the
parent
// message was downloaded just prior to the message
currently
// being processed, so scan the stored messages from
last to
first
AnsiString MsgIdToFind(pStart, pEnd-pStart+1);
for(int idx = Messages->Count-1; idx >= 0; --idx)
{
if( Messages->Strings[idx] == MsgIdToFind )
// MsgID was found
return (TTreeNode*)Messages->Objects[idx];
}
// keep going
pEnd = (pStart-1);
}
}
// MsgID not found
return NULL;
}
//...
TStringList *Messages = new TStringList;
try
{
TStringList *XOverData = new TStringList;
try
{
int ArticleIndex, ByteCount, LineCount;
AnsiString Subject, From, MsgId, References, ExtraData;
TDateTime dtDate;
TTreeNode *Node;
// use whatever article indexes you are actually downloading
IdNNTP1->XOVER(AnsiString(IdNNTP1->MsgLow) + "-" +
AnsiString(IdNNTP1->MsgHigh), XOverData);
TreeView1->Items->BeginUpdate();
try
{
for(int x = 0; x < XOverData->Count; ++x)
{
IdNNTP1->ParseXOVER(XOverData->Strings[x],
ArticleIndex,
Subject, From, dtDate, MsgId, References, ByteCount, LineCount, ExtraData);
Node = FindParentMessage(Messages, References);
if( Node )
Node = TreeView1->Items->AddChild(Node, Subject);
else
Node = TreeView1->Items->Add(NULL, Subject);
}
Messages->AddObject(MsgId, Node);
}
}
__finally {
TreeView1->Items->EndUpdate();
}
}
__finally {
delete XOverData;
}
}
__finally {
delete Messages;
}
Re: Tranlation problem
Author: Remy Lebeau (TeamB)
Date: Fri, 15 Dec 2006 06:33
Date: Fri, 15 Dec 2006 06:33
66 lines
3047 bytes
3047 bytes
"Roger Hemme" <rog@net.nl> wrote in message news:45823D21.30200@net.nl...
> The BCB-code:
In that case, your translation is pretty much right on. A directly
translation is as follows:
function FindParentMessage(Messages: TStrings; References: String):
TTreeNode;
var
pFirst, pStop, pStart, pEnd: PChar;
MsgIdToFind: String;
Idx: Integer;
begin
Result := nil;
if Length(References) = 0 then Exit;
pFirst := PChar(References);
pStop := (pFirst+2);
pEnd := AnsiLastChar(References);
// scan through the reference list from back to front as
// newer messages in a discussion are at the end of the list
while pEnd > pStop do
begin
// find the end of the MsgID
while (pEnd > pStop) and (pEnd^ <> '>') do Dec(pEnd);
if pEnd = pStop then Break;
// find the start of the MsgID
pStart := (pEnd-1);
while (pStart >= pFirst) and (pStart^ <> '<') do Dec(pStart);
if pStart < pFirst then Break;
// find the MsgID in the stored list. chances are, the parent
// message was downloaded just prior to the message currently
// being processed, so scan the stored messages from last to
first
SetString(MsgIdToFind, pStart, Longint(pEnd-pStart)+1);
for Idx := Messages.Count-1 downto 0 do
begin
if Messages.Strings[idx] = MsgIdToFind then
begin
// MsgID was found
Result := TTreeNode(Messages.Objects[idx]);
Exit;
end;
end;
// keep going
pEnd := (pStart-1);
end;
// MsgID not found
end;
// the rest I already gave you earlier...
With that said, you still haven't explained what exactly you are having a
problem with. Just saying that something is not working says nothing about
the actual problem.
Gambit
Re: Translation problem
Author: Roger Hemme
Date: Fri, 15 Dec 2006 15:23
Date: Fri, 15 Dec 2006 15:23
19 lines
1829 bytes
1829 bytes
Remy Lebeau (TeamB) skrev: > > With that said, you still haven't explained what exactly you are having a > problem with. Just saying that something is not working says nothing about > the actual problem. > Well, Remy, i just got home from work, and realize that i should not post on the usenet when i'm stressed and in a hurry (like yesterday) It's working now! The /threading/ (of the articles) works now, and i don't know why it didn't work previously. I'm sorry for the inconvenience, and i thank you very much for helping me with this problem. I will study the code, and hopefully i'll learn a lot from this. Again, thank you!
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads