🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #264637

Re: [40tude] Edit -> Find regular expression?

#264637
From: mike
Date: Fri, 22 Jan 2021 06:50
116 lines
4391 bytes
 wrote:

> program OnBeforeSavingMessage;
> function StringReplace(S, OldPattern, NewPattern: string): string;
> function OnBeforeSendingMessage(var Message: TStringlist; Servername:

Compilation error:
Failed when compiling [Error] (43:5): Type mismatch

Does anyone know why I get a "type mismatch" on these lines when I use them
as an OnBeforeSavingMessage but I do NOT get the type mismatch error when I
compile the same script as an OnBeforeSendingMessage?
    NewStr := Copy(NewStr, Offset + Length(OldPattern), 2147483647);
    SearchStr := Copy(SearchStr, Offset + Length(Patt), 2147483647);
The type mismatch is shown in red for "2147483647".

(1) I only get the type mismatch when I compile the script below 
    as an OnBeforeSavingMessage.
(2) When I compile the script below as an OnBeforeSendingMessage, 
    I don't get the compilation error.
(3) But, either way, the umlaut testcase doesn't get changed to "ue"
    TEST  ä ö ü ü ö ä

I'm trying to figure out what the code does so I can figure out why it's not
working, but I don't know what the purpose of the "2147483647" is yet.

Do you?
-- 
program OnBeforeSavingMessage;

function StringReplace(S, OldPattern, NewPattern: string): string;
var
  SearchStr, Patt, NewStr: string;
  Offset: Integer;
begin
  SearchStr := S;
  Patt := OldPattern;
  NewStr := S;
  Result := '';
  while SearchStr <> '' do
  begin
    Offset := AnsiPos(Patt, SearchStr);
    if Offset = 0 then
    begin
      Result := Result + NewStr;
      Break;
    end;
    Result := Result + Copy(NewStr, 1, Offset - 1) + NewPattern;
    NewStr := Copy(NewStr, Offset + Length(OldPattern), 2147483647);
    SearchStr := Copy(SearchStr, Offset + Length(Patt), 2147483647);
  end;
end;

function OnBeforeSavingMessage(var Message: TStringlist; Servername:
string; IsEmail: boolean):boolean;
var s:string;
begin
result:=true;
s:=message.text;
s:=StringReplace(s,'ü','ue');
s:=stringreplace(s,'ö','oe');
s:=stringreplace(s,'ä','ae');
s:=stringreplace(s,'Ü','Ue');
s:=stringreplace(s,'Ö','Oe');
s:=stringreplace(s,'Ä','Ae');
s:=stringreplace(s,'ß','ss');
message.text:=s;
end;

begin
end.
-- 
program OnBeforeSendingMessage;

function StringReplace(S, OldPattern, NewPattern: string): string;
var
  SearchStr, Patt, NewStr: string;
  Offset: Integer;
begin
  SearchStr := S;
  Patt := OldPattern;
  NewStr := S;
  Result := '';
  while SearchStr <> '' do
  begin
    Offset := AnsiPos(Patt, SearchStr);
    if Offset = 0 then
    begin
      Result := Result + NewStr;
      Break;
    end;
    Result := Result + Copy(NewStr, 1, Offset - 1) + NewPattern;
    NewStr := Copy(NewStr, Offset + Length(OldPattern), 2147483647);
    SearchStr := Copy(SearchStr, Offset + Length(Patt), 2147483647);
  end;
end;

function OnBeforeSendingMessage(var Message: TStringlist; Servername:
string; IsEmail: boolean):boolean;
var s:string;
begin
result:=true;
s:=message.text;
s:=StringReplace(s,'ü','ue');
s:=stringreplace(s,'ö','oe');
s:=stringreplace(s,'ä','ae');
s:=stringreplace(s,'Ü','Ue');
s:=stringreplace(s,'Ö','Oe');
s:=stringreplace(s,'Ä','Ae');
s:=stringreplace(s,'ß','ss');
message.text:=s;
end;

begin
end.
-- 
Technical Details
Message-ID: <rudsj7$vme$1@solani.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!not-for-mail
References: <ru5nfg$si7$1@solani.org> <3xo0b6k69bco$.dlg@v.nguard.lh> <ruagkd$j08$1@solani.org> <1gf2aqovcfhb8.dlg@v.nguard.lh> <rubuok$j1b$1@solani.org> <rubvif$jli$1@solani.org> <1pop06goudbzf$.dlg@b.rose.tmpbox.news.arcor.de> <rud043$e9r$1@solani.org>

Show Full Headers
Complete Article Headers
Message-ID: <rudsj7$vme$1@solani.org>
Subject: Re: [40tude] Edit -> Find regular expression?
Date: Fri, 22 Jan 2021 12:20:16 +0530
From: mike <this@address.is.invalid>
References: <ru5nfg$si7$1@solani.org> <3xo0b6k69bco$.dlg@v.nguard.lh> <ruagkd$j08$1@solani.org> <1gf2aqovcfhb8.dlg@v.nguard.lh> <rubuok$j1b$1@solani.org> <rubvif$jli$1@solani.org> <1pop06goudbzf$.dlg@b.rose.tmpbox.news.arcor.de> <rud043$e9r$1@solani.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!not-for-mail
User-Agent: 40tude_Dialog/2.0.15.41 (0c24496a.39.280)
Cancel-Lock: sha1:X5HANIevEDFDMm12pBgvJ3XPtYM=
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0
Newsgroups: news.software.readers
Injection-Info: solani.org; logging-data="32462"; mail-complaints-to="abuse@news.solani.org"
Content-Type: text/plain; charset="us-ascii"
Injection-Date: Fri, 22 Jan 2021 06:50:16 -0000 (UTC)
X-User-Id: eJwNx0kRwDAMBDBKPjc1HB81fwjJSyNXMPoYHObr2yGSxcTv1QS21R5C6rMD1AjKyrFW7H+WbRyqNRIfpVxPPRVz