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
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-