[fpc-devel] va(r)_arg vs open array

ik idokan at gmail.com
Thu Oct 5 13:09:01 CEST 2006


On 10/5/06, Bisma Jayadi <bisma at brawijaya.ac.id> wrote:
> > For example:
> If this is really the case that cause you demand var_args feature, then
> obviously you have problem with your software design. I agree with Marco. :) I
> wrote a program to solve a problem exactly like this without need of var_args
> feature. Even though var_args is provided, I won't use it either, since -IMO-
> var_args isn't the correct way to solve this kind of problem.
>
> The above problem can be solved easily with a simple "find-and-replace"-like
> algorithm. IMO, basically this is a template filling. Just put a unique tags
> on every place that need to be filled with a value. Parse the template and
> replace every tag with appropriate value and format. Likely this must be done
> by a specialized class for this purpose.
>
> With this solution, my program can do the job very well with more than 200
> kind of tags on more than 20 kind of templates (and increasing by the day).
> The users can even build their own template(s) through a template builder
> wizard from my application. I believe the wizard can't be easily build just
> using var_args. Your sample above, using my solution will become a template
> like this (less or more):
>
> > For example:
> >
> > <DATE:TODAY>
> >
> > Hello <CUSTOMER:TITLE>. <CUSTOMER:LAST_NAME>,
> >
> > Thank you for interesting in our <PRODUCT:NAME>.
> > <CUSTOMER:FIRST_NAME> we are more then happy to help you and give you
> > additional information about <PRODUCT:NAME>.
> >
> > You can either call us at the phone number of 1234567890 extension
> > <PHONE_EXT:CUSTOMER_SUPPORT> for customer support.
> >
> > You can also contact our sails department at phone number 1234567890
> > extension <PHONE_EXT:PRODUCT_UPGRADE> for upgrading your <PRODUCT:NAME>,
> > or just to ask additional questions.
> >
> > You can also contact our support team at the email of <PRODUCT:EMAIL>.
> >
> > Regards,
> >
> > <DIRECTOR:FULL_NAME>,
> > <JOB_TITLE:DIRECTOR>.
>
> Or am I missing something here?

You are missing something :)

First of all it is sad that format is not useful for such a thing, but
my example about using a lot of parameters for a function, and you
will need to keep on either rewrite a function, or overload a function
with new parameters, when you do not have array of const/var args ...
It was giving for "show me one use ..." so I gave one :)

BTW I would have either solve this problem for real, either by using
tags like you have used, and the use of replaceall function, or if the
letter was a inside my source, I would have do it

'Hello ' + Fields.Name + ...

Depends on the situation I could design it.

However a reason that you must agree that it's easier to use array of
const rather then working harder is to use SQL parameters.

Because if you will not use array of char, you will doomed to do it in
a very very very hard way, and not that easy as well imho:

with array of const:

params([a,b,c,d,e,f,g,h,a,a,a,z]); //Some DB can allow you to create
temporary variable, so it can save you to call the same paramter more
then once ...

Without array of const:

sql.getparam(1).value := a;
sql.getparam(2).value := b;
sql.getparam(3).value := c;
...
sql.getparam(7000000).value := z;

There is a Delphi component for BDE (if I remember correctly) that
works like the second one ... on both cases you need to count
parameters, and place it on the right order... and a "for" loop will
not help with the parameters values, unless it saved at the same order
as the getparam order ... and then you made a double work ...


>
> -Bee-
>
> has Bee.ography at:
> http://beeography.wordpress.com

Ido
ik.homelinux.org/index.rhtml/home ;) (still under havy work btw)

P.S. Now I actually need to answer Marco, although I thought to stop
this threading :(



More information about the fpc-devel mailing list