Difference between revisions of "OBJECT()"

From Lianjapedia
Jump to: navigation, search
(Description)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
 
Function to create an anonymous object
 
Function to create an anonymous object
 
  
 
==Syntax==
 
==Syntax==
 
OBJECT([<property value> | <property name> => <property value> [,...]])
 
OBJECT([<property value> | <property name> => <property value> [,...]])
 
  
 
==See Also==
 
==See Also==
[[ACLASS()]], [[ADDPROPERTY()]], [[AMEMBERS()]], [[CLASS]], [[CLASS - Methods]], [[CLASS - Parameters]], [[CLASS - Properties]], [[CLASS - Scoping]], [[COMPOBJ()]], [[CREATEOBJECT()]], [[DEFINE CLASS]], [[DISPLAY CLASSES]], [[DODEFAULT()]], [[FOREACH]], [[LIST CLASSES]], [[LOADOBJECT()]], [[METHOD]], [[NEWOBJECT()]], [[PRINT_HTML()]], [[PRINT_JSON()]], [[PRINT_R()]], [[PRINT_XML()]], [[REMOVEPROPERTY()]], [[REQUIRE_ONCE()]], [[SAVEOBJECT()]], [[SQL SELECT]], [[WITH]]
+
[[ACLASS()]], [[ADDPROPERTY()]], [[AMEMBERS()]], [[COMPOBJ()]], [[CREATEOBJECT()]], [[DEFINE CLASS]], [[DISPLAY CLASSES]], [[DODEFAULT()]], [[FOREACH]], [[LIST CLASSES]], [[LOADOBJECT()]], [[NEWOBJECT()]], [[PRINT_HTML()]], [[PRINT_JSON()]], [[PRINT_R()]], [[PRINT_XML()]], [[REMOVEPROPERTY()]], [[REQUIRE_ONCE()]], [[SAVEOBJECT()]], [[SQL SELECT]], [[WITH]], [[ARRAY()]]
 
+
  
 
==Description==
 
==Description==
 
The OBJECT() function is used to create an anonymous object.  Properties are declared in a comma-separated list. Properties can be values only, <property value>, in which case they are given an automatically generated name: 00000001, 00000002 ... Property names can be specified using the <property name> => <property value> syntax.  The OBJECT() function can also be included within the <property value> definition.  The OBJECT() function returns an object.
 
The OBJECT() function is used to create an anonymous object.  Properties are declared in a comma-separated list. Properties can be values only, <property value>, in which case they are given an automatically generated name: 00000001, 00000002 ... Property names can be specified using the <property name> => <property value> syntax.  The OBJECT() function can also be included within the <property value> definition.  The OBJECT() function returns an object.
+
 
 +
The difference between OBJECT() and ARRAY() is that ARRAY() creates a dynamic array and OBJECT() creates an anonymous object that has “factory methods”:
 +
 
 +
addproperty(name, expression)
 +
 
 +
removeproperty(name)
 +
 
 +
clone()
 +
 
 +
list()
 +
 
 +
equals( anotherobject )
  
 
==Example==
 
==Example==
Line 25: Line 33:
 
Memory Variables:
 
Memory Variables:
 
------------------------
 
------------------------
CUSTOMER                         Object (refptr OBJECT, refcnt 1)
+
private(2):
.CUSTNAME                         Character 'A Buyer Ltd.'
+
CUSTOMER   Object (refptr OBJECT, refcnt 1)
.CURRENTORDER                     Object (refptr OBJECT, refcnt 1)
+
.CUSTNAME   Character 'A Buyer Ltd.'
  .ORD_ID                           Character '00001'
+
.CURRENTORDER Object (refptr OBJECT, refcnt 0)
  .ORD_DATE                         Date 11/17/2009
+
  .ORD_ID   Character '00001'
  .ORD_TOTAL                         Numeric 1599  (1599.000000000)
+
  .ORD_DATE Date 12/21/2012
  .ORDERITEMS                       Object (refptr OBJECT, refcnt 1)
+
  .ORD_TOTAL Numeric 1599  (1599.000000000)
   .00000001                          Character '10 reams A4 paper'
+
  .ORDERITEMS Object (refptr OBJECT, refcnt 0)
   .00000002                          Character '500 business cards'
+
   [1]      Character '10 reams A4 paper'
   .00000003                          Character '500 black ballpoint pens'
+
   [2]      Character '500 business cards'
 +
   [3]      Character '500 black ballpoint pens'
  
Total of 10 variables defined and 784 bytes used.
+
** Total of ** 10 variables defined and 864 bytes used.
 
</code>
 
</code>
  
==Products==
 
Lianja, Lianja Server
 
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 
[[Category:Objects]]
 
[[Category:Objects]]
[[Category:Objects Functions]]
 
 
[[Category:Lianja VFP Extensions]]
 
[[Category:Lianja VFP Extensions]]
 
[[Category:VFP Function Extensions]]
 
[[Category:VFP Function Extensions]]

Latest revision as of 01:45, 27 August 2022

Purpose

Function to create an anonymous object

Syntax

OBJECT([<property value> | <property name> => <property value> [,...]])

See Also

ACLASS(), ADDPROPERTY(), AMEMBERS(), COMPOBJ(), CREATEOBJECT(), DEFINE CLASS, DISPLAY CLASSES, DODEFAULT(), FOREACH, LIST CLASSES, LOADOBJECT(), NEWOBJECT(), PRINT_HTML(), PRINT_JSON(), PRINT_R(), PRINT_XML(), REMOVEPROPERTY(), REQUIRE_ONCE(), SAVEOBJECT(), SQL SELECT, WITH, ARRAY()

Description

The OBJECT() function is used to create an anonymous object. Properties are declared in a comma-separated list. Properties can be values only, <property value>, in which case they are given an automatically generated name: 00000001, 00000002 ... Property names can be specified using the <property name> => <property value> syntax. The OBJECT() function can also be included within the <property value> definition. The OBJECT() function returns an object.

The difference between OBJECT() and ARRAY() is that ARRAY() creates a dynamic array and OBJECT() creates an anonymous object that has “factory methods”:

addproperty(name, expression)

removeproperty(name)

clone()

list()

equals( anotherobject )

Example

customer = object("custname" => "A Buyer Ltd.", ;
  "currentorder" => object("ord_id" => "00001", "ord_date" => date(),"ord_total" => 1599,;
  "orderitems" =>  object("10 reams A4 paper","500 business cards",;
                         "500 black ballpoint pens")))
display memory
 
Memory Variables:
------------------------
private(2):
CUSTOMER   Object (refptr OBJECT, refcnt 1)
.CUSTNAME   Character 'A Buyer Ltd.'
.CURRENTORDER Object (refptr OBJECT, refcnt 0)
 .ORD_ID    Character '00001'
 .ORD_DATE  Date 12/21/2012
 .ORD_TOTAL  Numeric 1599  (1599.000000000)
 .ORDERITEMS Object (refptr OBJECT, refcnt 0)
  [1]      Character '10 reams A4 paper'
  [2]      Character '500 business cards'
  [3]      Character '500 black ballpoint pens'

** Total of ** 10 variables defined and 864 bytes use
** Total of ** 10 variables defined and 864 bytes used.