Navigation:  Samples >

Properties sample

Previous pageReturn to chapter overviewNext page

This example creates a user-defined property for the current database, sets its Type and Value properties, and appends it to the Properties collection of the database. Then the example enumerates all properties in the database. See the properties listed in the Property summary topic for additional examples.

 

FUNCTION Start

LOCAL dbeng                                AS DaoDBEngine

LOCAL db                                AS DaoDatabase

LOCAL prpUserDefined, prpEnum AS Daoproperty

LOCAL uVar AS USUAL

LOCAL i AS LONG

LOCAL oErr                                AS USUAL

LOCAL cbOldErr                        AS CODEBLOCK

Set COlor TO w+/b

cls

BEGIN SEQUENCE

 cbOldErr := ErrorBlock({|oErr|_Break(oErr)})

 uVar := "This is a user-defined property."

 dbeng        := DaoDbEngine{}        

 // Open the database.

 db := dbeng:OpenDatabase("\VO2Jet\Northwind.mdb",NIL,NIL,NIL)

 

 // Delete property if it alread exists

 BEGIN SEQUENCE

         db:Properties:Delete("UserDefinedProperty")

 END

 // Create user-defined property.

 prpUserDefined := db:CreateProperty( "UserDefinedProperty",  dbText, uVar ,NIL)

 

 

 // Append property to current database.

 

 db:Properties:Append(prpUserDefined)

 

 // Enumerate all properties of current database.

 ? "Properties of Database", db:Name

 ? "Name, type, value, Inherited"

 FOR i := 1 TO db:Properties:Count

     prpEnum := db:Properties:[item,i]

     ? Str(I,3), PadR(prpEnum:Name,20), PadR(DaoDataType(prpEnum:TYpe),10)

     // Some properties have no value !

     BEGIN SEQUENCE

             ?? "",prpEnum:Value

     RECOVER

             ?? " ** No value **"

         END

     ?? " ",prpEnum:Inherited

     inkey(.2)

 NEXT

   wait

   cls

   ? "Now remove User Defined property"

 ? "Properties of Database", db:Name

 ? "Name, type, value, Inherited"

 

   db:Properties:Delete( "UserDefinedProperty")

 FOR i := 1 TO db:Properties:Count

     prpEnum := db:Properties:[item,i]

     ? Str(I,3), PadR(prpEnum:Name,20), PadR(DaoDataType(prpEnum:TYpe),10)

     // Some properties have no value !

     BEGIN SEQUENCE

             ?? "",prpEnum:Value

     RECOVER

             ?? " ** No value **"

         END

     ?? " ",prpEnum:Inherited

     inkey(.2)

 NEXT

 

 

RECOVER USING oErr

 Eval(cbOldErr,oErr)        

END

wait

RETURN