Board index » delphi » Did I say something wrong??

Did I say something wrong??

Quote
Jack D wrote in message <1jxB9.8340$bh1.593...@news1.telusplanet.net>...

[...]

Quote
>It seems though, that the language itself doesn't support what I would
consider
>to be a simple task. i.e. some sort of 'split' function. (...)
>                     ...this TRegExpr package.

You are confusing the language (which should supply data types)
with the run-time library (which should supply ready-made code).

The run-time library is extensible: you can add your own library
code - but if nobody has written the exact code you want, it's
up to you to do so.

Delphi gives you all the building blocks to build your own split
function. Or an entire regular expressions package, and in fact
somebody already did so. That you consider it incomplete, or
poorly documented, is between you and him.

Perl and Pascal are very different languages. Perl is big on
regular expressions. Pascal is not. That simple. It's strengths
are in other areas. If what you want to do is better done in
Perl (which is possible), you should by all means do it in Perl.

When doing things in Delphi, it's best to do them the Delphi way.
We have seen a thousand posts here of people who complain about
poor PChar support. Well, that figures. String handling in Delphi
is geared towards Delphi strings. PChars are a C compatibility
feature. You may need them because Windows is C-oriented, but
doing anything with PChars except copying them to and from strings
is misguided.

It's happened before that somebody asked "When I do <this>, why
is it so hard?" and the answer was: because that's not how it's
done in Delphi. Tell us what your program does (_what_, not _how_),
and we'll be happy to explain how we'd solve it. In real life,
you'd know when to use a hammer and when to use an axe. Knowing
when to use Delphi and when to stick to Perl is no different.
Well, not much.

(BTW, the answer is of course that against plate armour you'd use
a hammer, and against most everything else the axe.)

Groetjes,
Maarten Wiltink

 

Re:Did I say something wrong??


In article <3dd76f2a$0$46599$e4fe5...@news.xs4all.nl>, "Maarten Wiltink"

Quote
<maar...@kittensandcats.net> writes:
>that against plate armour you'd use
>a hammer

I reckon that shaped semtex is the language of choice in that case, although
for body armour nothing semed proof against the English long-bow (the French
have never forgiven us <g>).

Alan Lloyd
alangll...@aol.com

Re:Did I say something wrong??


Hi Jack,

Quote
>I was hoping to use a regular expression (coming from a perl background - I
>would feel more 'at home'). Hence I had downloaded TRegExpr. Does anyone have
>experience with this module?

I'm using it in a project - for searching only, not splitting (I wasn't
quite aware it would do that). What do you need to know, specifically?

Here's how you use the component for searching - not sure if you need this,
but anyway, here it is. The component has a number of properties
corresponding to various modifier parameters in a perl regexp. So you need
to set it up initially, and assign the regexp to the Expression property:

{ var RE : TRegExpr; }

  with RE do
  begin
    Expression := 'your_regexp_here';
    ModifierI := true; // case insensitive search
    ModifierX := true; // ExtendedSyntax
    ModifierG := false; // 'greedy" regexps
    // etc., all modifiers are documented in component source
  end;

next, you tell the component to compile the regexp - this is where it will
throw an exception on sytnax errors:

    try
      // precompile RegExp. This also checks for RegExp format errors
      RE.Compile;
    except
      On E : ERegExpr do
      begin
        showmessage( strERRRegexpInvalid + #13#10 + E.Message );
        exit;
      end;
    end;

And finally, you search:

ExpressionFound := RE.Exec( SourceText );

BTW, are you aware that the recent releases of ActiveState Perl support
'embedding' perl in applications, via a dll? You can execute Perl scripts
(and evaluate expressions) directly from your Delphi app. If you ever try
that, I'd love to see a demo, because it would come in handy for my
open-source project but my Perl is too rusty these days :-)

.marek

--
No ads, no nags freeware: http://keynote.prv.pl
(KeyNote, PhoneDeck, KookieJar, Oubliette)

"So tell me, just how long have you had this feeling that no one
is watching you?" (Christopher Locke: Entropy Gradient Reversals)

Re:Did I say something wrong??


On 17 Nov 2002 16:18:06 GMT, alangll...@aol.com (AlanGLLoyd) wrote:

Quote
>In article <3dd76f2a$0$46599$e4fe5...@news.xs4all.nl>, "Maarten Wiltink"
><maar...@kittensandcats.net> writes:

>>that against plate armour you'd use
>>a hammer

>I reckon that shaped semtex is the language of choice in that case, although
>for body armour nothing semed proof against the English long-bow (the French
>have never forgiven us <g>).

I suspect a large part of that was down to lurking behind caltrops and
sharpened stakes.

An arquebot (crossbow) was around long before then - and they are just
as deadly.

As for rate of fire - probably higher than a musket...

There is probably an algorithm there somewhere -
    Success = units * (firepower / necessary_relocation )

or: Snipers need a stable platform ...

Best that programmers stay away from such areas.

Quote
>Alan Lloyd
>alangll...@aol.com

Re:Did I say something wrong??


In article <3dd7f363.46616...@news.u-net.com>,

Quote
Bounce_It_je...@iss.u-net.com_.bin (J French) writes:
>An arquebot (crossbow) was around long before then - and they are just
>as deadly.

The French army's use of mercenary Genoan cross-bow men at Agincourt failed
because the strings got wet and seriously reduced the range. The cross-bows
could not be readily re-strung. English archers kept their strings (and a spare
string) nice and dry next to other essential parts of their anatomical
equipment.

Quote
>As for rate of fire - probably higher than a musket...

Yes much higher, but slower than an English archer. English archers could
achieve a long term average of six aimed shots/min, with a maximum of ten aimed
shots/min. As cross-bows had to be rewound they were much slower.

I think also that the English arrow-heads were a better "penetrate and
continue" design against armour than the cross-bow bolts.

Guns were not readily available at the time of Agincourt. But interestingly
just as the English archers made a resounding point to (allegedly socially
superior) men on horses with swords, there _were_ a few guns at Agincourt,
which later were to see off the long-bow.

The long-bows and arrows were more technically advanced that one would think.
Robert Hardy (the actor) has written a very interesting book on the subject.

Alan Lloyd
alangll...@aol.com

Re:Did I say something wrong??


Quote
AlanGLLoyd wrote:
> I reckon that shaped semtex is the language of choice in that case,
> although for body armour nothing semed proof against the English long-
> bow (the French have never forgiven us <g>).

We thank Yew

Sorry, I'll get my coat.

Re:Did I say something wrong??


Very interesting, thanks,

On 18 Nov 2002 14:07:38 GMT, alangll...@aol.com (AlanGLLoyd) wrote:

Quote
>In article <3dd7f363.46616...@news.u-net.com>,
>Bounce_It_je...@iss.u-net.com_.bin (J French) writes:

>>An arquebot (crossbow) was around long before then - and they are just
>>as deadly.

>The French army's use of mercenary Genoan cross-bow men at Agincourt failed
>because the strings got wet and seriously reduced the range. The cross-bows
>could not be readily re-strung. English archers kept their strings (and a spare
>string) nice and dry next to other essential parts of their anatomical
>equipment.

>>As for rate of fire - probably higher than a musket...

>Yes much higher, but slower than an English archer. English archers could
>achieve a long term average of six aimed shots/min, with a maximum of ten aimed
>shots/min. As cross-bows had to be rewound they were much slower.

>I think also that the English arrow-heads were a better "penetrate and
>continue" design against armour than the cross-bow bolts.

>Guns were not readily available at the time of Agincourt. But interestingly
>just as the English archers made a resounding point to (allegedly socially
>superior) men on horses with swords, there _were_ a few guns at Agincourt,
>which later were to see off the long-bow.

>The long-bows and arrows were more technically advanced that one would think.
>Robert Hardy (the actor) has written a very interesting book on the subject.

>Alan Lloyd
>alangll...@aol.com

Re:Did I say something wrong??


Use my function, it is flexible and fast.  You can pass in any
delimiter (character to split on).  Note : You need to create a
TStringList instance to pass into it.

Paul Scott
aspsc...@tcp.co.uk
^^ Remove as "anti-spam" prefix

type
  TCharSet = set of char;

...

procedure DelimitedTextToStrings(const DelimitedText : string;
  Delimiter, TextQualifierChar : char; IgnoredChars : TCharSet;
TextStrings : TStrings);
// Action : Converts Delimited Text into strings in a stringlist
// Notes  : Params are as follows...
//   DelimitedText - Delimited string to process
//   Delimiter - character which separates strings  e.g. ',' or #9
//   TextQualifierChar - Optional character which denotes text e.g. "
or ' or #0 if none required
//   IgnoredChars - set of characters (max 31) to skip during
conversion e.g. Control characters [#1..#30]
var
  P, P1 : PChar;
  S : string;
begin
  Exclude(IgnoredChars, #0);
  Exclude(IgnoredChars, Delimiter);
  Exclude(IgnoredChars, TextQualifierChar);
  with TextStrings do
  begin
    BeginUpdate;
    try
      Clear;
      P := PChar(DelimitedText);
      while P^ in IgnoredChars do   // Ignore junk characters
        P := CharNext(P);
      while P^ <> #0 do             // while not at end of string
(null terminator)
      begin
        if P^ = TextQualifierChar then            // If we are at
start of qualified string
          S := AnsiExtractQuotedStr(P, TextQualifierChar)  // Extract
qualifiers
        else
        begin
          P1 := P;                  // otherwise
          while not (P^ in (IgnoredChars + [#0, Delimiter])) do
            P := CharNext(P);
          SetString(S, P1, P - P1); // copy unquoted string
        end;
        Add(S);                          // Add stored string to
stringlist
        while P^ in IgnoredChars do      // Ignore junk characters
          P := CharNext(P);
        if P^ = Delimiter then
          repeat                         // Move to start of next
string
            P := CharNext(P);
          until not (P^ in IgnoredChars);
      end;
    finally
      EndUpdate;
    end;
  end;
end;

Paul Scott

On Sat, 16 Nov 2002 19:49:17 GMT, "Jack D" <goodcal...@hotmail.com>
wrote:

Quote

>It seems though, that the language itself doesn't support what I would consider
>to be a simple task. i.e. some sort of 'split' function. From the answers so
>far, it seems that everyone writes their own procedures or functions for such a
>thing. I assumed (??) that the language would easily support this functionality.

>Regular Expressions are a powerful thing! Something I can't do without. So,
>while I now have a temporary solution to this particular problem, I will
>continue to battle with this TRegExpr package.

>Thanks again to all.

>Jack
>PS..BTW this perl one-liner does this task automatically without a regex :)

>@array = split(/\~/,$string);

Go to page: [1] [2]

Other Threads