Data Access Worldwide Knowledge Base
Article ID 2128 Article Title INFO: More on Structs Article URL http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2128 KBase Category VDF11 Date Created 05/27/2005 Last Edit Date 06/20/2005
Article Text
QUESTION:
1) Would I be able to use the new struct in linked lists, hashes, etc?
2) Some examples don't have size defined. Can I assume that they will work just like strings?
3) In the example below, how do I reference this stuff? If I want the 'street' of shipping address, what do I use?
Struct tUSAddress
String street
String city
String state
Integer zipCode
End_Struct
Struct tPurchaseOrder
Integer orderNumber
Date orderDate
tUSAddress shippingAddress
tUSAddress billingAddress
...
End_Struct
ANSWER:
1) You can create linked lists, even indirect recursive struct declarations, through arrays. It's just like with pointers in C, only a lot easier as you do not have to manage the memory manually.
An example of indirect recursion through an array is an internal structure we use with Web Services:
Struct tValueTree
String sValue
tValueTree[] children
End_Struct
2) Visual DataFlex struct types can make use of all Visual DataFlex data types, including String. This means that a String member is a String. The Visual DataFlex String type is a dynamically sized string, so you do not need to specify a size.
Some Visual DataFlex types are directly compatible with C, like Integer; whereas others aren't, like String. This is just like using C++ std::string inside a struct. std::string is not compatible with C, but that doesn't mean you can't use it in a struct. It just won't be compatible with C, as C does not understand std::string.
If you need C string compatibility, then you have to declare the struct in a C'ish way. In C++ that means you cannot use the std::string class for example, you have to resort to char[]. Same thing applies in Visual DataFlex, you cannot use the String type if you want C compatibility, as C does not understand the DataFlex String type. So you would use Char[] or Char[5] for example.
But remember that all Visual DataFlex types, including String, Date and Number for example, are supported in Struct declarations. So you can take full advantage of all types in Visual DataFlex. But of course, only the subset of all DataFlex types that are also available in C, are compatible with C struct declarations.
3) Create a variable for the struct you use and then access the member you need:
tPurchaseOrder myOrder
string sShipToStreet
Move myOrder.shippingAddress.street to sShipToStreet
If you use the tUSAddress struct, you can have something like:
tUSAddress myAddress
string sStreet
Move myAddress.Street to sStreet
Contributed By:
Sonny Falk
Company: Data Access Worldwide
Web Site: http://www.dataaccess.com
Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.
The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.