Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Safe Table Opening Code -How's This?
Message
From
26/10/2001 16:28:18
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
26/10/2001 12:03:28
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00573683
Message ID:
00573989
Views:
17
>>What sort of safety do you want?
>>
>>In general, if you see that you need to do the same thing over and over again, it seems a good idea to create a function or method, as you did here.
>>
>>If you use an object instead, you can save yourself the trouble of closing the table in code: the table is closed in the class'es Destroy() event.
>
>Hilmar,
>
>This is only true if the class has (or is) a private datasession (or if the class is part of a dataenvironment that closes the tables). Otherwise, the tables will stay open.

No: what I meant is that you create an object (or class) to open a table. The object remembers the name of the alias, and closes it, when the corresponding variable goes out of scope. Thus, after doing this programming once, in the "Table_Open" class, you save yourself the table closing later.

All this isn't required when you have a private datasession, since the tables are closed automatically, anyway.

Let me illustrate:
Function SomeProcess
local loTableObject
* This command will open the table, with the specified index, assign buffering, etc.
loTableObject = CreateObject("cTableObject", TableName, Index, Alias, Buffering, etc.)
...
Further processing here
...
* Here, at the EndFunc, the table gets closed, because:
* 1) Variable loTableObject gets destroyed (out of scope),
* 2) This, in turn, invokes loTableObject.Destroy(),
* 3) which was appropriately programmed to close the table.
EndFunc
Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform