🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
12 messages
12 total messages Started by Warwick Fri, 26 Dec 2003 09:51
[Dialog] Scripting String type
#139860
Author: Warwick
Date: Fri, 26 Dec 2003 09:51
26 lines
2049 bytes
Hi,
I have tried the following two statements in a script.
VAR
      i, pos : integer;
      tmp : string;
    BEGIN  
      tmp := Copy( memo.Lines.Strings[i], 1, 255 ); 
  or  tmp := memo.Lines.Strings[i];
   END;
In each case tmp might have basically anything at all assigned into it
execpt the string in memo.Lines.Strings[i].
Often is has the first chars up to a space, or the chars after the first
space, sometimes nothing at all ... or other interesting behaviour.
Can I include a file in the uses clause and access the AnsiString type?

I have created a dbug function to set watches and breakpoints and examined
the contents of memo. Nothing wrong with the contents of the TStrings
object. 
Problem is in assignments and I'd prefer not to get bogged down with basic
string functions when I am already familiar with AnsiString.

Any help most appreciated.

 
best
Warwick
Re: [Dialog] Scripting String type
#139867
Author: Liz Albin
Date: Fri, 26 Dec 2003 14:04
8 lines
1348 bytes
On Fri, 26 Dec 2003 22:51:38 +1300, Warwick wrote:

>       tmp := Copy( memo.Lines.Strings[i], 1, 255 );

What's i?  In the code you posted there's no indication that you've set
it.
-- 
liz
Re: [Dialog] Scripting String type
#139907
Author: Warwick
Date: Fri, 26 Dec 2003 23:59
24 lines
1891 bytes
On Fri, 26 Dec 2003 09:04:41 -0500, Liz Albin wrote:

> On Fri, 26 Dec 2003 22:51:38 +1300, Warwick wrote:
> 
>>       tmp := Copy( memo.Lines.Strings[i], 1, 255 );
> 
> What's i?  In the code you posted there's no indication that you've set
> it.

Some value between 0 and memo.Count-1.
No I did not post the entire loop its very messy.
I have found the exercise frustrating so a lot of code is commented out and
kludged on the fly as I use the scripting host to experiment with Pascal.
The problem seems confined to the string type.


At this point I am starting to wonder if it wont be easier to rewrite
dialog in CBuilder and then code what I want to do.

Do you know if I can access AnsiString class?

cheers
Warwick
Re: [Dialog] Scripting String type
#139912
Author: Liz Albin
Date: Sat, 27 Dec 2003 01:29
13 lines
1565 bytes
On Sat, 27 Dec 2003 12:59:17 +1300, Warwick wrote:

> Some value between 0 and memo.Count-1.
> No I did not post the entire loop its very messy.

If you don't post the loop. it's impossible to help you with code.  I
will say what people tend to say in Delphi and C++ tech groups:
post a complete small (<50 lines) program that demonstrates your
problem.

-- 
thanks
liz
Re: [Dialog] Scripting String type
#139913
Author: Warwick
Date: Sat, 27 Dec 2003 01:54
236 lines
8290 bytes
On Fri, 26 Dec 2003 20:29:33 -0500, Liz Albin wrote:

> On Sat, 27 Dec 2003 12:59:17 +1300, Warwick wrote:
> 
>> Some value between 0 and memo.Count-1.
>> No I did not post the entire loop its very messy.
> 
> If you don't post the loop. it's impossible to help you with code.  I
> will say what people tend to say in Delphi and C++ tech groups:
> post a complete small (<50 lines) program that demonstrates your
> problem.

Demo Follows - stripped down as best as I can.
Here is a better example.
memo is a TMemo object in the Global Space.
Info is a TSTringList Object in the Global Space.
Main calls Analyseallmessages.
Analyseallmessages pastes the contents of each message to the clipboard
then calls EXtractHeaderValue.
ExtractHeaderValue is a legacy name, all this function now does is 
-save the contents of the memo to file
-iterate over the strings in memo and copy them into the string variable
tmp. 
-add tmp to info.
-When finished iterating over memos strings save info to file.

At the end of this process you might hope that memo and inf are the same.
However they are not and you can see the value in tmp has had newlines
inserted somehow.

Thats why I want to ditch it and use the AnsiString object.

If you can cast any light on the matter Liz I would be very grateful.

best
Warwick


<Code>
Program MyTest;
uses
   forms,   
   textfile,
   stdctrls;

   CONST
   OutputPath = 'C:\Documents And Settings\My Documents\Dialog Outputs\';
   
  

    VAR
    memo : TMemo; {work-around for copyclipboard function for lines}
    HostForm : TForm;   
    PrevMessageId : string;
    MessageID : string;
    Info : TStringList; {to be replace by appropriate data structure for
other analysis}
    Halt : boolean; {work around of the propagation of an exception that
abort the script}

   
    
//-----------------------------------------------------------------------------------------------------
    FUNCTION EmptyClipboard:boolean; external 'EmptyClipboard@user32.dll
stdcall';
    FUNCTION OpenClipboard(hWndNewOwner: INTEGER):boolean; external
'OpenClipboard@user32.dll stdcall';
    FUNCTION CloseClipboard:boolean; external 'CloseClipboard@user32.dll
stdcall';

//-----------------------------------------------------------------------------------------------------
    PROCEDURE ClearCLipboard;
    {to avoid side effects: if an empty selection is copyed in the
clipboard}
    BEGIN
      OpenClipboard(Application.Handle);
      EmptyClipboard;
      CloseClipboard;
    END;
//-----------------------------------------------------------------------------------------------------   


//-----------------------------------------------------------------------------------------------------   
    FUNCTION GetClipboardData():boolean; //Copy Clipboard data to Global
DummyMemo
    begin                                // return true if data copied.
        memo.Clear();
        memo.PasteFromClipboard();
        result := memo.Lines.Count > 0;
     end;
//-----------------------------------------------------------------------------------------------------  

 FUNCTION ExtractHeaderValue( HeaderKey : string ): string;
    VAR
      i, strpos : integer;
      tmp : string;
    BEGIN  
      Result := '';  
      i := 0;  
      
      memo.Lines.SaveToFile(OutputPath+'memotest.txt');
      
     WHILE (i < memo.Lines.count-1) AND (Result = '') DO
     BEGIN
         
         tmp :=  memo.Lines.Strings[i];   
         info.Add(tmp);               
         i := i+1;
      END;  
      Info.SaveToFile(OutputPath + 'Info.txt'); 
      Halt := true; //parse one post only
    END;


//----------------------------------------------------------------------------------------------------
   PROCEDURE AnalyseAllMessages();
   
   VAR
      MessageCounter : INTEGER;
      Done:boolean;
      MessageId, PrevMessageId:string;    
      
   BEGIN
         MessageCounter:=0;
         PrevMessageId := ' ';
         Done := false;
         WHILE( NOT Done ) Do
         Begin
            ClearClipboard();
            ADo('ArticlePane');
            ADo('ShowHeaders');  
            ADo('SelectAll'); 
            ADo('Copy');  
            if GetClipboardData() then        
                       MessageId := ExtractHeaderValue('Message-ID');
            if( Halt = true ) then
               Done := true;
            if MessageId = PrevMessageId then
                 Done := true; 
           ADo('NextMessageInHistory');      
           
         end;//while
   END;
//-----------------------------------------------------------------------------------------------------

BEGIN   //main
   try
      lockdisplay;   
      HostForm := TForm.Create(Nil); 
      memo := TMemo.Create(HostForm);
      memo.Parent := HostForm;
      Info := TStringList.Create();
      AnalyseAllMessages();
      ADo('CollapseAllThreads');	
   finally
   	memo.Free();
   	Info.Free();   
  	unlockdisplay;
   end;

End.
</Code>

<Contents of memo>
Hi,
I have tried the following two statements in a script.
VAR
      i, pos : integer;
      tmp : string;
    BEGIN  
      tmp := Copy( memo.Lines.Strings[i], 1, 255 ); 
  or  tmp := memo.Lines.Strings[i];
   END;
In each case tmp might have basically anything at all assigned into it
execpt the string in memo.Lines.Strings[i].
Often is has the first chars up to a space, or the chars after the first
space, sometimes nothing at all ... or other interesting behaviour.
Can I include a file in the uses clause and access the AnsiString type?

I have created a dbug function to set watches and breakpoints and examined
the contents of memo. Nothing wrong with the contents of the TStrings
object. 
Problem is in assignments and I'd prefer not to get bogged down with basic
string functions when I am already familiar with AnsiString.

Any help most appreciated.

 
best
Warwick
</Contents of memo>


<Contents of Info>
Hi,
I have tried the following two 
statements in a script.
VAR
      i, pos : integer;
      tmp : string;
    BEGIN  
      tmp := Copy( 
memo.Lines.Strings[i], 1, 255 ); 
  or  tmp := memo.Lines.Strings[i];
   END;
In each case tmp might have 
basically anything at all assigned into 
it
execpt the string in 
memo.Lines.Strings[i].
Often is has the first chars up to a 
space, or the chars after the first
space, sometimes nothing at all ... or 
other interesting behaviour.
Can I include a file in the uses clause 
and access the AnsiString type?

I have created a dbug function to set 
watches and breakpoints and 
examined
the contents of memo. Nothing wrong 
with the contents of the TStrings
object. 
Problem is in assignments and I'd 
prefer not to get bogged down with 
basic
string functions when I am already 
familiar with AnsiString.

Any help most appreciated.

 
best


</Contents of Info>
Re: [Dialog] Scripting String type
#139914
Author: Liz Albin
Date: Sat, 27 Dec 2003 02:05
31 lines
2030 bytes
On Sat, 27 Dec 2003 14:54:11 +1300, Warwick wrote:

> Any help most appreciated.

Looking at this function:

 FUNCTION ExtractHeaderValue( HeaderKey : string ): string;
    VAR
      i, strpos : integer;
      tmp : string;
    BEGIN  
      Result := '';  
      i := 0;  
      
      memo.Lines.SaveToFile(OutputPath+'memotest.txt');
      
     WHILE (i < memo.Lines.count-1) AND (Result = '') DO
     BEGIN
         
         tmp :=  memo.Lines.Strings[i];   
         info.Add(tmp);               
         i := i+1;
      END;  
      Info.SaveToFile(OutputPath + 'Info.txt'); 
      Halt := true; //parse one post only
    END;

I notice that neither Result nor ExtractHeaderValue is ever set.
Perhaps this is a problem?
-- 
liz
Re: [Dialog] Scripting String type
#139915
Author: Warwick
Date: Sat, 27 Dec 2003 02:31
318 lines
10071 bytes
On Fri, 26 Dec 2003 21:05:36 -0500, Liz Albin wrote:

> On Sat, 27 Dec 2003 14:54:11 +1300, Warwick wrote:
> 
>> Any help most appreciated.
> 
> Looking at this function:
> 
>  FUNCTION ExtractHeaderValue( HeaderKey : string ): string;
>     VAR
>       i, strpos : integer;
>       tmp : string;
>     BEGIN  
>       Result := '';  
>       i := 0;  
>       
>       memo.Lines.SaveToFile(OutputPath+'memotest.txt');
>       
>      WHILE (i < memo.Lines.count-1) AND (Result = '') DO
>      BEGIN
>          
>          tmp :=  memo.Lines.Strings[i];   
>          info.Add(tmp);               
>          i := i+1;
>       END;  
>       Info.SaveToFile(OutputPath + 'Info.txt'); 
>       Halt := true; //parse one post only
>     END;
> 
> I notice that neither Result nor ExtractHeaderValue is ever set.
> Perhaps this is a problem?

there is an empty string assigned into result immediately after BEGIN.

Oddly Statements like 
	ExtractHeaderValue := 'AString';
will not compile in Dialog, only functions that are of the form
	Result := 'AString';
I posted on that irregularity to another newsgroup and was made aware of
what the Result variable is.

It might be a problem but it does not readily explain why the strings added
to Info have been broken up with newlines that should not be there.

It is easily tested, so I have replaced that function with a procedure
called ATest.

The problem of newlines breaking up the value in tmp persists :(

btw, I am very grateful for your input :)

new listing and output follow
<Code>
rogram MyTest;
uses
   forms,   
   textfile,
   stdctrls;

   CONST
   OutputPath = 'C:\Documents And Settings\Warwick Barnes\My
Documents\Dialog Outputs\';
   
  

    VAR
    memo : TMemo; {work-around for copyclipboard function for lines}
    HostForm : TForm;   
    PrevMessageId : string;
    MessageID : string;
    Info : TStringList; {to be replace by appropriate data structure for
other analysis}
    Halt : boolean; {work around of the propagation of an exception that
abort the script}

   
    
//-----------------------------------------------------------------------------------------------------
    FUNCTION EmptyClipboard:boolean; external 'EmptyClipboard@user32.dll
stdcall';
    FUNCTION OpenClipboard(hWndNewOwner: INTEGER):boolean; external
'OpenClipboard@user32.dll stdcall';
    FUNCTION CloseClipboard:boolean; external 'CloseClipboard@user32.dll
stdcall';

//-----------------------------------------------------------------------------------------------------
    PROCEDURE ClearCLipboard;
    {to avoid side effects: if an empty selection is copyed in the
clipboard}
    BEGIN
      OpenClipboard(Application.Handle);
      EmptyClipboard;
      CloseClipboard;
    END;
//-----------------------------------------------------------------------------------------------------   


//-----------------------------------------------------------------------------------------------------   
    FUNCTION GetClipboardData():boolean; //Copy Clipboard data to Global
DummyMemo
    begin                                // return true if data copied.
        memo.Clear();
        memo.PasteFromClipboard();
        result := memo.Lines.Count > 0;
     end;
//-----------------------------------------------------------------------------------------------------  

 PROCEDURE ATest();
    VAR
      i : integer;
      tmp : string;
    BEGIN  
      
      i := 0;  
      
      memo.Lines.SaveToFile(OutputPath+'memotest.txt');
      
     WHILE (i < memo.Lines.count-1) do
     BEGIN
         
         tmp :=  memo.Lines.Strings[i];   
         info.Add(tmp);               
         i := i+1;
      END;  
      Info.SaveToFile(OutputPath + 'Info.txt'); 
      Halt := true; //parse one post only
    END;


//----------------------------------------------------------------------------------------------------
   PROCEDURE AnalyseAllMessages();
   
   VAR
      MessageCounter : INTEGER;
      Done:boolean;
      MessageId, PrevMessageId:string;    
      
   BEGIN
         MessageCounter:=0;
         PrevMessageId := ' ';
         Done := false;
         WHILE( NOT Done ) Do
         Begin
            ClearClipboard();
            ADo('ArticlePane');
            ADo('ShowHeaders');  
            ADo('SelectAll'); 
            ADo('Copy');  
            if GetClipboardData() then        
                       ATest();
            if( Halt = true ) then
               Done := true;
            if MessageId = PrevMessageId then
                 Done := true; 
           ADo('NextMessageInHistory');      
           
         end;//while
   END;
//-----------------------------------------------------------------------------------------------------

BEGIN   //main
   try
      lockdisplay;   
      HostForm := TForm.Create(Nil); 
      memo := TMemo.Create(HostForm);
      memo.Parent := HostForm;
      Info := TStringList.Create();
      AnalyseAllMessages();
      ADo('CollapseAllThreads');	
   finally
   	memo.Free();
   	Info.Free();   
  	unlockdisplay;
   end;

End.
</Code>

<Contents of Memo>
Path:
news.xtra.co.nz!enews.sgi.com!tdsnet-transit!newspeer.tds.net!diablo.voicenet.com!rcn!feed3.news.rcn.net!not-for-mail
From: Liz Albin <lizalbin@yahooNotThis.com>
Subject: Re: [Dialog] Scripting String type
Newsgroups: news.software.readers
User-Agent: 40tude_Dialog/2.0.9.1
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
References: <1b6u8igdk34r0$.a6efjxy49gi9.dlg@40tude.net>
<3fec4018$0$4751$61fed72c@news.rcn.com>
<cpggdl6fzows$.e509dp8nmg5f.dlg@40tude.net>
<3fece09c$0$4761$61fed72c@news.rcn.com>
<jajhoqqonc5e.1q1m1s6565rcw$.dlg@40tude.net>
Date: Fri, 26 Dec 2003 21:05:36 -0500
Archive: yes
Lines: 31
Message-ID: <3fece90f$0$4754$61fed72c@news.rcn.com>
NNTP-Posting-Host: 207.237.44.199
X-Trace: 1072490767 reader3.news.rcn.net 4754 207.237.44.199:4173
X-Complaints-To: abuse@rcn.com
Xref: news.xtra.co.nz news.software.readers:120639

On Sat, 27 Dec 2003 14:54:11 +1300, Warwick wrote:

> Any help most appreciated.

Looking at this function:

 FUNCTION ExtractHeaderValue( HeaderKey : string ): string;
    VAR
      i, strpos : integer;
      tmp : string;
    BEGIN  
      Result := '';  
      i := 0;  
      
      memo.Lines.SaveToFile(OutputPath+'memotest.txt');
      
     WHILE (i < memo.Lines.count-1) AND (Result = '') DO
     BEGIN
         
         tmp :=  memo.Lines.Strings[i];   
         info.Add(tmp);               
         i := i+1;
      END;  
      Info.SaveToFile(OutputPath + 'Info.txt'); 
      Halt := true; //parse one post only
    END;

I notice that neither Result nor ExtractHeaderValue is ever set.
Perhaps this is a problem?
-- 
liz


</Contents of Memo>

<Contents of Info>
Path: 
news.xtra.co.nz!enews.sgi.com!tdsnet
-transit!newspeer.tds.net!diablo.voice
net.com!rcn!feed3.news.rcn.net!not-f
or-mail
From: Liz Albin 
<lizalbin@yahooNotThis.com>
Subject: Re: [Dialog] Scripting String 
type
Newsgroups: news.software.readers
User-Agent: 40tude_Dialog/2.0.9.1
MIME-Version: 1.0
Content-Type: text/plain; 
charset="us-ascii"
Content-Transfer-Encoding: 7bit
References: 
<1b6u8igdk34r0$.a6efjxy49gi9.dlg@4
0tude.net> 
<3fec4018$0$4751$61fed72c@new
s.rcn.com> 
<cpggdl6fzows$.e509dp8nmg5f.dlg@
40tude.net> 
<3fece09c$0$4761$61fed72c@new
s.rcn.com> 
<jajhoqqonc5e.1q1m1s6565rcw$.dlg
@40tude.net>
Date: Fri, 26 Dec 2003 21:05:36 
-0500
Archive: yes
Lines: 31
Message-ID: 
<3fece90f$0$4754$61fed72c@news
.rcn.com>
NNTP-Posting-Host: 207.237.44.199
X-Trace: 1072490767 
reader3.news.rcn.net 4754 
207.237.44.199:4173
X-Complaints-To: abuse@rcn.com
Xref: news.xtra.co.nz 
news.software.readers:120639

On Sat, 27 Dec 2003 14:54:11 
+1300, Warwick wrote:

> Any help most appreciated.

Looking at this function:

 FUNCTION ExtractHeaderValue( 
HeaderKey : string ): string;
    VAR
      i, strpos : integer;
      tmp : string;
    BEGIN  
      Result := '';  
      i := 0;  
      
      
memo.Lines.SaveToFile(OutputPath+'
memotest.txt');
      
     WHILE (i < memo.Lines.count-1) 
AND (Result = '') DO
     BEGIN
         
         tmp :=  memo.Lines.Strings[i];   
         info.Add(tmp);               
         i := i+1;
      END;  
      Info.SaveToFile(OutputPath + 
'Info.txt'); 
      Halt := true; //parse one post only
    END;

I notice that neither Result nor 
ExtractHeaderValue is ever set.
Perhaps this is a problem?
-- 

</Contents of Info>
Re: [Dialog] Scripting String type
#139916
Author: Liz Albin
Date: Sat, 27 Dec 2003 02:33
9 lines
1650 bytes
On Sat, 27 Dec 2003 15:31:11 +1300, Warwick wrote:

> there is an empty string assigned into result immediately after BEGIN.

The loop continues until you reset result (or the counter goes all the
way through)  this could be a problem.  Probably not related to the
problem you're seeing however :(
-- 
liz
Re: [Dialog] Scripting String type
#139917
Author: Warwick
Date: Sat, 27 Dec 2003 02:47
5 lines
1549 bytes
Actually I changed view to monospace and it looks like
tmp is wrapping at 36 chars.
ie if tmp length > 36 it inserts a newline at tmp[36];
	
Like some kind of wrapping function inherent in string?
Re: [Dialog] Scripting String type
#139919
Author: Liz Albin
Date: Sat, 27 Dec 2003 02:55
7 lines
1557 bytes
On Sat, 27 Dec 2003 15:47:27 +1300, Warwick wrote:

> Like some kind of wrapping function inherent in string?

No, but you could turn wordwrap off in your tmemo.
-- 
liz
Re: [Dialog] Scripting String type
#139920
Author: Warwick
Date: Sat, 27 Dec 2003 03:18
32 lines
2938 bytes
On Fri, 26 Dec 2003 21:55:59 -0500, Liz Albin wrote:

> Path: news.xtra.co.nz!enews.sgi.com!tdsnet-transit!newspeer.tds.net!diablo.voicenet.com!rcn!feed3.news.rcn.net!not-for-mail
> From: Liz Albin <lizalbin@yahooNotThis.com>
> Subject: Re: [Dialog] Scripting String type
> Newsgroups: news.software.readers
> User-Agent: 40tude_Dialog/2.0.9.1
> MIME-Version: 1.0
> Content-Type: text/plain; charset="us-ascii"
> Content-Transfer-Encoding: 7bit
> References: <1b6u8igdk34r0$.a6efjxy49gi9.dlg@40tude.net> <3fec4018$0$4751$61fed72c@news.rcn.com> <cpggdl6fzows$.e509dp8nmg5f.dlg@40tude.net> <3fece09c$0$4761$61fed72c@news.rcn.com> <jajhoqqonc5e.1q1m1s6565rcw$.dlg@40tude.net> <3fece90f$0$4754$61fed72c@news.rcn.com> <thmjf3ul88gq.v292hic8wob1$.dlg@40tude.net> <44cpi4l5qccw.15kjivh2ryg8z$.dlg@40tude.net>
> Date: Fri, 26 Dec 2003 21:55:59 -0500
> Archive: yes
> Lines: 7
> Message-ID: <3fecf4de$0$4746$61fed72c@news.rcn.com>
> NNTP-Posting-Host: 207.237.44.199
> X-Trace: 1072493790 reader3.news.rcn.net 4746 207.237.44.199:4517
> X-Complaints-To: abuse@rcn.com
> Xref: news.xtra.co.nz news.software.readers:120644
> 
> On Sat, 27 Dec 2003 15:47:27 +1300, Warwick wrote:
> 
>> Like some kind of wrapping function inherent in string?
> 
> No, but you could turn wordwrap off in your tmemo.

LOL BINGO! Problem solved.

thanks ever so much - compliments of the season to you :)

cheers
Warwick
Re: [Dialog] Scripting String type
#139921
Author: Liz Albin
Date: Sat, 27 Dec 2003 03:26
7 lines
1641 bytes
On Sat, 27 Dec 2003 16:18:38 +1300, Warwick wrote:

> thanks ever so much - compliments of the season to you :)

You're very welcome, Merry Happy back at you :)
-- 
liz
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