Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / User defined data types as function arguments

Author
Message
madbilly
21
Years of Service
User Offline
Joined: 20th Mar 2003
Location: United Kingdom
Posted: 28th Mar 2003 23:05
Hi all,

I've got a couple of queries I'm hoping that somebody can help me with?

Firstly, I was wondering if it is possible to pass user defined data types as arguments to functions, and also if they can be used as return types.

e.g.


Is this possble? I get a parameter mismatch error on the initial parse when compiling in the last line of the code.

Secondly, why can't an array be included as a field in a user defined type? It's a bit of a pain. Could a pointer to the memory location of the array be used instead? Even if it could this is also a pain! I'm not really sure how pointers work in DB - the help file warns you off them!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Mar 2003 01:28 Edited at: 29th Mar 2003 01:29
No, you can't pass types either to or from a function. And to cut short the next question, yes we've been asking, and yes it will probably come sometime

For your second question, it's simply a matter of compiler complexity. DBPro uses a system to provide variable length arrays that doesn't fit into the type scheme very well - the compiler would need to do a more complex 'deep' copy to copy them - although this must already happen in some form with strings.

You could simulate arrays with a pointer to memory you allocate yourself, but that gives you the problem of remembering to allocate the memory, copy the memory when copying types, deallocate the memory when you're done, and accessing that memory safely when reading/writing the value.

Best to do something like this:



You still have to remember to do the copying, but you don't have to remember to allocate/deallocate and read/write access is safe and easy.
madbilly
21
Years of Service
User Offline
Joined: 20th Mar 2003
Location: United Kingdom
Posted: 29th Mar 2003 13:51
I seriously hope that the language is made more powerful - it's not even a great thing to ask for is it? Otherwise what's the point in having user defined types if they have to be broken down and passed by individual field every time you make a function call. Whilst I am a beginner to DB I'm not a beginner to programming and I'm having to "unlearn" a lot of the stuff so I can think in terms of how DB operates. Keeping the same ease of use but also adding more powerful languages capabilities for more advanced coders would help condiderably - Patch 5 anyone?! (unlikely I know )

Login to post a reply

Server time is: 2024-11-10 05:11:11
Your offset time is: 2024-11-10 05:11:11