Article View: news.software.readers
Article #139913Re: [Dialog] Scripting String type
From: Warwick
Date: Sat, 27 Dec 2003 01:54
Date: Sat, 27 Dec 2003 01:54
236 lines
8290 bytes
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>
Technical Details
Message-ID:
<jajhoqqonc5e.1q1m1s6565rcw$.dlg@40tude.net>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!internal1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!border3.nntp.aus1.giganews.com!nntp.giganews.com!diablo.voicenet.com!tdsnet-transit!newspeer.tds.net!enews.sgi.com!news.xtra.co.nz!53ab2750!not-for-mailReferences:
<1b6u8igdk34r0$.a6efjxy49gi9.dlg@40tude.net> <3fec4018$0$4751$61fed72c@news.rcn.com> <cpggdl6fzows$.e509dp8nmg5f.dlg@40tude.net> <3fece09c$0$4761$61fed72c@news.rcn.com>Show Full Headers
Complete Article Headers
Message-ID: <jajhoqqonc5e.1q1m1s6565rcw$.dlg@40tude.net> Subject: Re: [Dialog] Scripting String type Date: Sat, 27 Dec 2003 14:54:11 +1300 From: Warwick <wjcb@extra.co.nz> 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> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!internal1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!border3.nntp.aus1.giganews.com!nntp.giganews.com!diablo.voicenet.com!tdsnet-transit!newspeer.tds.net!enews.sgi.com!news.xtra.co.nz!53ab2750!not-for-mail 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 Lines: 236 NNTP-Posting-Host: 219.88.59.85 X-Complaints-To: newsadmin@xtra.co.nz X-Trace: news.xtra.co.nz 1072490048 219.88.59.85 (Sat, NNTP-Posting-Date: Sat, 27 Dec 2003 14:54:08 NZDT Organization: Xtra