Board index » delphi » Passing a string expression to be boolean evaluated

Passing a string expression to be boolean evaluated

Quote
p-mchar...@adfa.oz.au (Peter McHardie) wrote:
>I have tried looking everywhere in manuals, books etc to find a
>solution to my problem. Here it is :

>I wish to pass a lengthy string to be evaluated in an if..then
>expression to determine if a database record is to be processed

>Basically as follows

>var sMeetCondition : string

>begin
>   sMeetCondition := (PROJNO>=10) AND (PROJNO<=20) AND (AMT > 10,000);
>   while not Table1.EOF do
>      begin
>         if sMeetCondition then
>              ..... perform action;
>         Table1.Next;
>      end;

>end;

>sMeetCondition is built up from another part of the program, but is
>shown here as an example of the type of string that might be passed.

>Can anyone help in this matter. In a previous language I was able to
>pass it easily as a literal, but can't seem to here

>TIA

>Peter McHardie

I would have thought the best way to do what you want is to pass the
qualifier string to the database as part of a query so that your while
loop would retrieve only the selected/qualifying rows.  In general, it's
better to push this type of function down into the database software,
which is designed to do it, rather than writing your own code to get the
column names and their data types, evaluate the qualifying expressions,
possibly convert the expression to the column's data type, etc.

Just my $.02.

Rod

 

Re:Passing a string expression to be boolean evaluated


Hi,

You might be interested in evaluating our HyperTerp script language VCL
component, it's a drag and drop component that provides a a pascal like
script language that can be interpreted during runtime.

You can download a demo from our home page at
http://www.hyperact.com/demos.html

Ron.

In article <4ccvep$...@euryale.cc.adfa.oz.au>,

Quote
Peter McHardie <p-mchar...@adfa.oz.au> wrote:
>I have tried looking everywhere in manuals, books etc to find a
>solution to my problem. Here it is :

>I wish to pass a lengthy string to be evaluated in an if..then
>expression to determine if a database record is to be processed

>Basically as follows

>var sMeetCondition : string

>begin
>   sMeetCondition := (PROJNO>=10) AND (PROJNO<=20) AND (AMT > 10,000);
>   while not Table1.EOF do
>      begin
>         if sMeetCondition then
>              ..... perform action;
>         Table1.Next;
>      end;

>end;

>sMeetCondition is built up from another part of the program, but is
>shown here as an example of the type of string that might be passed.

>Can anyone help in this matter. In a previous language I was able to
>pass it easily as a literal, but can't seem to here

>TIA

>Peter McHardie

--
Ron Loewy, HyperAct, Inc. +1 (319) 351 8413  | rlo...@hyperact.com
Author of HLPDK/PA, CatMake, Interactive Help and HyperTerp.
Visit our home page at http://www.hyperact.com .

Re:Passing a string expression to be boolean evaluated


In article <4ccvep$...@euryale.cc.adfa.oz.au>,
   p-mchar...@adfa.oz.au (Peter McHardie) wrote:

Quote
>I have tried looking everywhere in manuals, books etc to find a
>solution to my problem. Here it is :

>I wish to pass a lengthy string to be evaluated in an if..then
>expression to determine if a database record is to be processed

>Basically as follows
>var sMeetCondition : string
>begin
>   sMeetCondition := (PROJNO>=10) AND (PROJNO<=20) AND (AMT > 10,000);
>   while not Table1.EOF do
>      begin
>         if sMeetCondition then
>              ..... perform action;
>         Table1.Next;
>      end;
>end;

>sMeetCondition is built up from another part of the program, but is
>shown here as an example of the type of string that might be passed.

>Can anyone help in this matter. In a previous language I was able to
>pass it easily as a literal, but can't seem to here

The problem is that the previous language must have been interpreted at run
time while Delphi is a fully compiled language so it can't have compiled the
code for something which will only exist at some time in the future.

In the example you give you could use a TQuery instead of a TTable and supply
the string as part of the SQL in which case it will work.  This may indirectly
give you much more power than was possible with the previous language as
you can use any valid SQL constructs in your string :-)

e.g.

var sMeetCondition : string

begin
   sMeetCondition := '(PROJNO>=10) AND (PROJNO<=20) AND (AMT > 10,000)';
   with Query1 do
   begin
      SQL.Clear;
      SQL.Add('select * from tablename where ' + sMeetCondition);
      Open;    
      while not EOF do
      begin
         ..... perform action; { you'll only get valid records in here }
         Next;
      end;
      Close;
   end;
end;

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bob Boffin          There's an old android saying. In binary it goes:
r...@rb.icl.co.uk    10001110110111000010111101110000100101010010
                    Makes you think huh?  Kryten - Red Dwarf
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Re:Passing a string expression to be boolean evaluated


I have tried looking everywhere in manuals, books etc to find a
solution to my problem. Here it is :

I wish to pass a lengthy string to be evaluated in an if..then
expression to determine if a database record is to be processed

Basically as follows

var sMeetCondition : string

begin
   sMeetCondition := (PROJNO>=10) AND (PROJNO<=20) AND (AMT > 10,000);
   while not Table1.EOF do
      begin
         if sMeetCondition then
              ..... perform action;
         Table1.Next;
      end;

end;

sMeetCondition is built up from another part of the program, but is
shown here as an example of the type of string that might be passed.

Can anyone help in this matter. In a previous language I was able to
pass it easily as a literal, but can't seem to here

TIA

Peter McHardie

Re:Passing a string expression to be boolean evaluated


Quote
Bob Boffin (r...@rb.icl.co.uk) wrote:

: The problem is that the previous language must have been interpreted at run
: time while Delphi is a fully compiled language so it can't have compiled the
: code for something which will only exist at some time in the future.

Just a small correction, Clipper does this and it's a pretty compiled
language..

   /Johan...!

Re:Passing a string expression to be boolean evaluated


Quote
w...@sophocles.algonet.se (Johan Alveborg) wrote:
>Bob Boffin (r...@rb.icl.co.uk) wrote:
>: The problem is that the previous language must have been interpreted at run
>: time while Delphi is a fully compiled language so it can't have compiled the
>: code for something which will only exist at some time in the future.
>Just a small correction, Clipper does this and it's a pretty compiled
>language..

A re-correction:  Clipper links in a runtime macro intepreter to
accomplish this.

Gaby
A minute passed.  Suddenly, another minute passed.
A frog farted ominously in the distance...

Re:Passing a string expression to be boolean evaluated


* In a message to All on 01-07-96, JOHAN ALVEBORG said the following:

JA> Just a small correction, Clipper does this and it's a pretty

Quote
> compiled language..

I thought Clipper was compiled to P-Code, which is still interpreted.

jim.sm...@lunatic.com  Written on 01-15-96 at 04:33p.
.

-- SRP 2.00 #0: Earning money would be fun if it wasn't so taxing.

----
The Lunatic Fringe * Richardson, TX * 214-235-5288 * Home Of FringeNet

Re:Passing a string expression to be boolean evaluated


jim.sm...@lunatic.com (Jim Smith)  wrote:

Quote
>* In a message to All on 01-07-96, JOHAN ALVEBORG said the following:
>JA> Just a small correction, Clipper does this and it's a pretty
>> compiled language..
>I thought Clipper was compiled to P-Code, which is still interpreted.

Its compiled.  Excellent language BTW.  I still use it to this day.

Brien King
bk...@primenet.com

Other Threads