对不起,说错了!应该是:Table2.Active:=False;不行,提示“Undeclared indentifier 'Table2' "Cannot assign to a read-only property"
你是不是用了数据库控件:TTable? TTable.Active是一个可读写的属性,不应该上面的提示!你试试Table2.Close; Specifies whether or not a dataset is open. property Active: Boolean; Description Use Active to determine or set whether a dataset is populated with data. When Active is False, the dataset is closed; the dataset cannot read or write data and data-aware controls can not use it to fetch data or post edits. When Active is True, the dataset can be populated with data. It can read data from a database or other source (such as a provider). Depending on the CanModify property, active datasets can post changes. Setting Active to True Generates a BeforeOpen event. Sets the dataset state to dsBrowse. Establishes a way to fetch data (typically by opening a cursor). Generates an AfterOpen event. If an error occurs while opening the dataset, dataset state is set to dsInactive, and any cursor is closed. Setting Active to False: 1 Triggers a BeforeClose event. 2 Sets the State property to dsInactive. 3 Closes the cursor. 4 Triggers an AfterClose event. An application must set Active to False before changing other properties that affect the status of a database or the controls that display data in an application. Note: Calling the Open method sets Active to True; calling the Close method sets Active to False.
"Cannot assign to a read-only property"
TTable.Active是一个可读写的属性,不应该上面的提示!你试试Table2.Close;
Specifies whether or not a dataset is open.
property Active: Boolean;
Description
Use Active to determine or set whether a dataset is populated with data. When Active is False, the dataset is closed; the dataset cannot read or write data and data-aware controls can not use it to fetch data or post edits. When Active is True, the dataset can be populated with data. It can read data from a database or other source (such as a provider). Depending on the CanModify property, active datasets can post changes.
Setting Active to True
Generates a BeforeOpen event.
Sets the dataset state to dsBrowse.
Establishes a way to fetch data (typically by opening a cursor).
Generates an AfterOpen event.
If an error occurs while opening the dataset, dataset state is set to dsInactive, and any cursor is closed.
Setting Active to False:
1 Triggers a BeforeClose event.
2 Sets the State property to dsInactive.
3 Closes the cursor.
4 Triggers an AfterClose event.
An application must set Active to False before changing other properties that affect the status of a database or the controls that display data in an application.
Note: Calling the Open method sets Active to True; calling the Close method sets Active to False.
cannot...没有了,但第一个提示依然有
你的table2是不是不在同一个文件中?
你几个文件的名称是什么?
uses unit1;
我在implementation中申明了uses Main_Window;
则调用要写:Form1.table2.Close;
还是你那个单元文件叫:main_window.pas
必须试form的名字!
单元名字和FORM的名字搞混了,呵呵。