Re: [BLACKBOX] Delphi-like parameters in Array Of Const

From: [at]} <Romiras>
Date: Mon, 11 Oct 2010 12:54:18 +0200

----boundary-LibPST-iamunique-1830989629_-_-
Content-type: text/plain

> A (type safe) way to do this in CP is to have one parameter which is a
> linked list of objects, each of which can be a different type. We use this
> technique extensively (in Delphi, CP and GPCP software) to provide a generic
> way of maintaining INI file / Windows registry values. It supports the use
> of string, boolean and integer data types.
>
> If you are only dealing with a few values then it is a simple problem
> deserving a simple solution. Call a separate procedure for each value you
> wish to format. If you have groups of similar calls then collect these into
> one procedure with a fixed number of parameters. It might require a little
> more typing but is likely to be more secure / reliable and be easier to
> comprehend and maintain in the long term.
Well. It's seems like a reasonable solution for me.

Here is a prototype of my Format procedure:

PROCEDURE Format* (template: ARRAY OF CHAR; args: VarList; VAR res:
ARRAY OF CHAR);
        VAR node: VarList; var: BaseType;
BEGIN
        res := template$; node := args;
        WHILE node # NIL DO
                var := node^.var;
                WITH
                        var: BoolType DO InterpretAsBool(var, res) |
                        var: IntType DO InterpretAsInt(var, res) |
                        var: RealType DO InterpretAsReal(var, res) |
                        var: CharType DO InterpretAsChar(var, res) |
                        (*var: SomeType DO InterpretAs(var, res)*)
                END;
                node := node^.next
        END;
END Format;


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1830989629_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDt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BTb21l
VHlwZSBETyBJbnRlcnByZXRBcyh2YXIsIHJlcykqKVxwYXINClx0YWIgXHRhYiBFTkQ7XHBhcg0K
XHRhYiBcdGFiIG5vZGUgOj0gbm9kZV4ubmV4dFxwYXINClx0YWIgRU5EO1xwYXINCkVORCBGb3Jt
YXQ7XHBhcg0KXHBhcg0KXHBhcg0KLS0tLVxwYXINClRvIHVuc3Vic2NyaWJlLCBzZW5kIGEgbWVz
c2FnZSB3aXRoIGJvZHkgIlNJR05PRkYgQkxBQ0tCT1giIHRvIExJU1RTRVJWQExJU1RTLk9CRVJP
Ti5DSH19AHZhciw=
----boundary-LibPST-iamunique-1830989629_-_---
Received on Mon Oct 11 2010 - 12:54:18 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:30 UTC