📄 openingtables.htm
字号:
<html>
<head>
<title>Opening and Closing Tables</title>
</head>
<!--#include virtual="/inc/header.php"-->
<table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#FFFFFF">
<tr>
<td align="left">
<span style="font-family:Helvetica,Arial; font-size:12pt; color:#000000"><b>Opening and Closing Tables
<br>
</b></span>
</td>
<td align="right">
<font face="Arial" size="2">
<a href="openingdatabases.htm">Previous</a>
<a href="overview.htm">Top</a>
<a href="executingqueries.htm">Next</a>
</font>
</td>
</tr>
</table>
<br><br>
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><b>Opening a table</b></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">
<br>
</span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
To read or write data in a table, an application must first open it.
<br>
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">1.</span></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>Place </b><b><a href=tabsdatabase.htm>TABSDatabase</a></b><b> and </b><b><a href=tabstable.htm>TABSTable</a></b><b> components</b> <span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">from the Absolute DB page of the Component palette to a data module or on a form, if you have not already done it.</span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">2.</span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>Set up TABSDatabase component</b>. <span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">Set the </span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">TABSDatabase.<span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><a href=tabsdatabase_databasename.htm>DatabaseName</a></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"> of the component to a unique value that will be used later to identify the database. Set the </span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">TABSDatabase.<span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><a href=tabsdatabase_databasefilename.htm>DatabaseFileName</a></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"> property to the name of the existing or new database file, if you have not already done it.
<br>
</span></span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">3.</span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>Set up TABSTable component. </b>Set the <span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">TABSTable.</span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><a href=tabsdataset_databasename.htm>DatabaseName</a></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"> property from the drop-down list of available TABSDatabase components. Set the TABSTable.</span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><a href=tabstable_tablename.htm>TableName</a></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"> property to the name of the table to create, if you have not already done it.
<br>
</span></span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">4.</span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><b>Set additional </b></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>TABSTable properties</b><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><b> (optional).</b></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"> Set </span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><a href=tabstable_readonly.htm>ReadOnly</a></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">, </span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><a href=tabstable_inmemory.htm>InMemory</a></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">, </span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><a href=tabstable_exclusive.htm>Exclusive</a></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"> properties of TABSTable component.
<br>
</span></span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">5.</span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><b><a href=openingdatabases.htm>Connect to a database</a></b></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><b> (optional).</b></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">
<br>
</span></span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"></span></td><td></td></tr></table><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">6. </span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><b>Open a table.</b></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"> You can open a table in two ways,
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"></td><td width="14"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">·</font></span></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Set the <a href=tdataset_active.htm>Active</a> property of the table to True, either at design time in the Object Inspector, or in code at runtime: ABSTable1.Active := True;
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"></td><td width="14"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">·</font></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Call the <a href=tdataset_open.htm>Open</a> method for the table at runtime, ABSTable1.Open;
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"></td><td width="14"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"></span></td><td></td></tr></table><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
<b>Example:
<br>
<br>
</b></span><span style="font-family:Courier New; font-size:8pt; color:#000000"> <span style="font-family:Courier New; font-size:8pt; color:#000080"><i>{set up database component}</i></span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">
<br>
ABSDatabase1.DatabaseName := <span style="font-family:Courier New; font-size:8pt; color:#000080">'emp_db'</span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">;
<br>
ABSDatabase1.DatabaseFileName := <span style="font-family:Courier New; font-size:8pt; color:#000080">'c:\data\employee_db.abs'</span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">;
<br>
<br>
<span style="font-family:Courier New; font-size:8pt; color:#000080"><i>{set up table component}</i></span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">
<br>
ABSTable1.DatabaseName := <span style="font-family:Courier New; font-size:8pt; color:#000080">'emp_db'</span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">;
<br>
ABSTable1.TableName := <span style="font-family:Courier New; font-size:8pt; color:#000080">'employee'</span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">;
<br>
<br>
<span style="font-family:Courier New; font-size:8pt; color:#000080"><i>{open table}</i></span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">
<br>
<b>if</b> (<b>not</b> ABSDatabase1.Exists) <b>then</b>
<br>
<b>raise</b> Exception.Create(<span style="font-family:Courier New; font-size:8pt; color:#000080">'Database file does not exist'</span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">);
<br>
<b>if</b> (<b>not</b> ABSTable1.Exists) <b>then</b>
<br>
<b>raise</b> Exception.Create(<span style="font-family:Courier New; font-size:8pt; color:#000080">'Table "employee" does not exist'</span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">);
<br>
ABSTable1.Active := True;</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
<br>
<br>
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><b>Closing a table
<br>
</b></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">
<br>
</span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">You can close a dataset in two ways,
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">·</font></span></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Set the <a href=tdataset_active.htm>Active</a> property of the table to False, either at design time in the Object Inspector, or in code at runtime, ABSTable1.Active := False;
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">·</font></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Call the <a href=tdataset_close.htm>Close</a> method for the dataset at runtime, ABSTable1.Close;
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"></span></span></td></tr></table>
<!--#include virtual="/inc/footer.php"-->
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -