An error occurred while running a component. Why? How can I change it?

Source: Internet
Author: User
An error occurred while running a component. Why? How can I change it? Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiDB/html/delphi_20061219211358215.html
I used delphi and SQL sever to build a Test Generation System. The BDE is used to connect and F9 runs normally. After the login interface appears, I can log on normally, however, an error message is displayed when you click the custom exam in the exam management module. However, if you close this prompt, the following page will be displayed. This error will not be reported when you click the custom exam next time.
Project project1.exe raised exception class EDatabase Error with message
Table_shijuan: cannot perform this operation on a close dataset process stopped use step or run to continue.

If I run project1.exe directly and click custom exam, this prompt will be displayed.
Table_shijuan cannot perform this operation on a close dataset

This is the code of unit10, which is used to customize the exam window. The fourth line is newshijuanhao: = DataModule4.Table _ shijuan. FieldValues ['jno'] + 1;
An error occurred. Could you help me?



Procedure Tdefinepaperform. FormShow (Sender: TObject );
Begin
DataModule4.Table _ shijuan. Last;
Newshijuanhao: = DataModule4.Table _ shijuan. FieldValues ['jno'] + 1;
DataModule4.Table _ shijuan. First;
End;

Procedure Tdefinepaperform. BitBtn1Click (Sender: TObject );
Begin
If addshijuan then
Begin
If checknewshijuan then
Begin

DataModule4.Table _ shijuan. Post;
DataModule4.Table _ shijuan. Close;
DataModule4.Table _ shijuan. Open;
Showmessage ('the new exam is added successfully! ');

Addshijuan: = false;
Inc (newshijuanhao );
// DataModule4.Table _ shijuan. UpdateRecord;
DBNavigator1.CanFocus;
BitBtn3.Enabled: = true;
BitBtn4.Enabled: = true;
End
Else
Exit;

End;
End;

Procedure Tdefinepaperform. DBEdit6Change (Sender: TObject );
Begin
Sum1: = 0;
If (DBEdit3.Text <> '') and (DBEdit6.Text <>'') then
Begin
Sum1: = sum1 + strtoint (DBEdit3.Text) * strtoint (DBEdit6.Text );
DBEdit9.Text: = inttostr (sum1 );
End;
End;

Procedure Tdefinepaperform. DBEdit7Change (Sender: TObject );
Begin
Sum2: = 0;
If (DBEdit4.Text <> '') and (DBEdit7.Text <>'') then
Begin
Sum2: = sum2 + strtoint (DBEdit4.Text) * strtoint (DBEdit7.Text );
DBEdit10.Text: = inttostr (sum2 );
End;
End;

Procedure Tdefinepaperform. DBEdit8Change (Sender: TObject );
Begin
Sum3: = 0;
If (DBEdit5.Text <> '') and (DBEdit8.Text <>'') then
Begin
Sum3: = sum3 + strtoint (DBEdit5.Text) * strtoint (DBEdit8.Text );
DBEdit11.Text: = inttostr (sum3 );
End;
End;

Procedure Tdefinepaperform. DBEdit13Change (Sender: TObject );
Begin
Sum4: = 0;
If (DBEdit12.Text <> '') and (DBEdit13.Text <>'') then
Begin
Sum4: = sum4 + strtoint (DBEdit12.Text) * strtoint (DBEdit13.Text );
DBEdit14.Text: = inttostr (sum4 );
End;
End;

Procedure Tdefinepaperform. DBEdit16Change (Sender: TObject );
Begin
Sum5: = 0;
If (DBEdit15.Text <> '') and (DBEdit16.Text <>'') then
Begin
Sum5: = sum5 + strtoint (DBEdit15.Text) * strtoint (DBEdit16.Text );
DBEdit17.Text: = inttostr (sum5 );
End;
End;

Procedure Tdefinepaperform. DBEdit17Change (Sender: TObject );
Begin
Allsum: = 0;
If (DBEdit9.Text <> '') and (DBEdit10.Text <>'') and (DBEdit11.Text <> '') and (DBEdit14.Text <>'') and (DBEdit17.Text <> '') then
Begin
Allsum: = allsum + sum1 + sum2 + sum3 + sum4 + sum5;
DBEdit2.Text: = inttostr (allsum );
End;
End;

Procedure Tdefinepaperform. DBEdit14Change (Sender: TObject );
Begin
Allsum: = 0;
If (DBEdit9.Text <> '') and (DBEdit10.Text <>'') and (DBEdit11.Text <> '') and (DBEdit14.Text <>'') and (DBEdit17.Text <> '') then
Begin
Allsum: = allsum + sum1 + sum2 + sum3 + sum4 + sum5;
DBEdit2.Text: = inttostr (allsum );
End;
End;

Procedure Tdefinepaperform. DBEdit11Change (Sender: TObject );
Begin
Allsum: = 0;
If (DBEdit9.Text <> '') and (DBEdit10.Text <>'') and (DBEdit11.Text <> '') and (DBEdit14.Text <>'') and (DBEdit17.Text <> '') then
Begin
Allsum: = allsum + sum1 + sum2 + sum3 + sum4 + sum5;
DBEdit2.Text: = inttostr (allsum );
End;
End;

Procedure Tdefinepaperform. DBEdit10Change (Sender: TObject );
Begin
Allsum: = 0;
If (DBEdit9.Text <> '') and (DBEdit10.Text <>'') and (DBEdit11.Text <> '') and (DBEdit14.Text <>'') and (DBEdit17.Text <> '') then
Begin
Allsum: = allsum + sum1 + sum2 + sum3 + sum4 + sum5;
DBEdit2.Text: = inttostr (allsum );
End;
End;

Procedure Tdefinepaperform. DBEdit9Change (Sender: TObject );
Begin
Allsum: = 0;
If (DBEdit9.Text <> '') and (DBEdit10.Text <>'') and (DBEdit11.Text <> '') and (DBEdit14.Text <>'') and (DBEdit17.Text <> '') then
Begin
Allsum: = allsum + sum1 + sum2 + sum3 + sum4 + sum5;
DBEdit2.Text: = inttostr (allsum );
End;
End;

Procedure Tdefinepaperform. DBEdit3Change (Sender: TObject );
Begin
Sum1: = 0;
If (DBEdit3.Text <> '') and (DBEdit6.Text <>'') then
Begin
Sum1: = sum1 + strtoint (DBEdit3.Text) * strtoint (DBEdit6.Text );
DBEdit9.Text: = inttostr (sum1 );
End;
End;

Procedure Tdefinepaperform. DBEdit4Change (Sender: TObject );
Begin
Sum2: = 0;
If (DBEdit4.Text <> '') and (DBEdit7.Text <>'') then
Begin
Sum2: = sum2 + strtoint (DBEdit4.Text) * strtoint (DBEdit7.Text );
DBEdit10.Text: = inttostr (sum2 );
End;
End;

Procedure Tdefinepaperform. DBEdit5Change (Sender: TObject );
Begin
Sum3: = 0;
If (DBEdit5.Text <> '') and (DBEdit8.Text <>'') then
Begin
Sum3: = sum3 + strtoint (DBEdit5.Text) * strtoint (DBEdit8.Text );
DBEdit11.Text: = inttostr (sum3 );
End;
End;

Procedure Tdefinepaperform. DBEdit12Change (Sender: TObject );
Begin
Sum4: = 0;
If (DBEdit12.Text <> '') and (DBEdit13.Text <>'') then
Begin
Sum4: = sum4 + strtoint (DBEdit12.Text) * strtoint (DBEdit13.Text );
DBEdit14.Text: = inttostr (sum4 );
End;
End;

Procedure Tdefinepaperform. DBEdit15Change (Sender: TObject );
Begin
Sum5: = 0;
If (DBEdit15.Text <> '') and (DBEdit16.Text <>'') then
Begin
Sum5: = sum5 + strtoint (DBEdit15.Text) * strtoint (DBEdit16.Text );
DBEdit17.Text: = inttostr (sum5 );
End;
End;

Procedure Tdefinepaperform. BitBtn3Click (Sender: TObject );
Var
I, j: integer;
Begin
Paperautoform. ProgressBar1.Position: = 0;
For I: = 1 to 800 do
Begin
Paperautoform. thao [I]: = 0;
Paperautoform. havetake [I]: = 0;
End;
For j: = 1 to 5 do
Begin
Paperautoform. diff [I]: = 0 ;;
End;
Paperautoform. Memo1.Text: = '';
Paperautoform. Show;
End;

Procedure Tdefinepaperform. BitBtn2Click (Sender: TObject );
Begin
DBNavigator1.BtnClick (nbCancel );
BitBtn3.Enabled: = true;
BitBtn4.Enabled: = true;
End;

It seems that DataModule4.Table _ shijuan is not enabled.

Unit Unit4;

Interface

Uses
SysUtils, Classes, DB, DBTables;

Type
TDataModule4 = class (TDataModule)
Table_u: TTable;
Performance_u: TDataSource;
Performance_choose: TDataSource;
Performance_filltext: TDataSource;
Performance_judge: TDataSource;
Performance_readpro: TDataSource;
Table_choose: TTable;
Table_filltext: TTable;
Table_judge: TTable;
Table_readpro: TTable;
Performance_procedure: TDataSource;
Table_procedure: TTable;
Table_uID: TStringField;
Table_umi: TStringField;
Table_uqx: TStringField;
Table_choosetno: TIntegerField;
Table_choosetigan: TMemoField;
Table_choosexa: TStringField;
Table_choosexb: TStringField;
Table_choosexc: TStringField;
Table_choosexd: TStringField;
Table_chooseanswer: TStringField;
Table_choosescore: TSmallintField;
Table_choosedifficulty: TStringField;
Table_choosenote: TStringField;
Performance_shijuan: TDataSource;
Table_shijuan: TTable;
Table_papermanager: TTable;
Performance_papermanager: TDataSource;
Database1: TDatabase;
Procedure Table_chooseBeforeDelete (DataSet: TDataSet );
Procedure Table_chooseAfterDelete (DataSet: TDataSet );
Procedure Table_filltextBeforeDelete (DataSet: TDataSet );
Procedure Table_judgeBeforeDelete (DataSet: TDataSet );
Procedure Table_readproBeforeDelete (DataSet: TDataSet );
Procedure Table_procedureBeforeDelete (DataSet: TDataSet );
Procedure Table_filltextAfterDelete (DataSet: TDataSet );
Procedure Table_judgeAfterDelete (DataSet: TDataSet );
Procedure Table_readproAfterDelete (DataSet: TDataSet );
Procedure Table_procedureAfterDelete (DataSet: TDataSet );
Procedure Table_shijuanBeforeDelete (DataSet: TDataSet );
Private
{Private declarations}
Public
{Public declarations}
End;

Var
DataModule4: TDataModule4;

Implementation

Uses Unit3, Unit6, Unit7, Unit8, Unit9, Unit11, Unit10;

{$ R *. dfm}

Procedure TDataModule4.Table _ chooseBeforeDelete (DataSet: TDataSet );
Begin
Mainform. updateno: = 0;

Mainform. updateno: = chooseform. Query1.FieldValues ['tno'];
// Exit;
// DBNavigator1.BtnClick (nbCancel );
// Showmessage ('select a chapter point ');

// Else
// Mainform. updateno: = table_choose ['tno'];
End;

Procedure TDataModule4.Table _ chooseAfterDelete (DataSet: TDataSet );
Begin
DataModule4.Table _ choose. Close;
DataModule4.Table _ choose. Open;
DataModule4.Table _ choose. Active: = false;
DataModule4.Table _ choose. Active: = true;

End;

Procedure TDataModule4.Table _ filltextBeforeDelete (DataSet: TDataSet );
Begin
Mainform. updateno: = 0;
Mainform. updateno: = filltextform. Query1.FieldValues ['tno'];
End;

Procedure TDataModule4.Table _ judgeBeforeDelete (DataSet: TDataSet );
Begin
Mainform. updateno: = 0;

Mainform. updateno: = judgeform. Query1.FieldValues ['tno'];
End;

Procedure TDataModule4.Table _ readproBeforeDelete (DataSet: TDataSet );
Begin
Mainform. updateno: = 0;
Mainform. updateno: = readproform. Query1.FieldValues ['tno'];
End;

Procedure TDataModule4.Table _ procedureBeforeDelete (DataSet: TDataSet );
Begin
Mainform. updateno: = 0;
Mainform. updateno: = procedureform. Query1.FieldValues ['tno'];
End;

Procedure TDataModule4.Table _ filltextAfterDelete (DataSet: TDataSet );
Begin
DataModule4.Table _ filltext. Close;
DataModule4.Table _ filltext. Open;
DataModule4.Table _ filltext. Active: = false;
DataModule4.Table _ filltext. Active: = true;
End;

Procedure TDataModule4.Table _ judgeAfterDelete (DataSet: TDataSet );
Begin
DataModule4.Table _ judge. Close;
DataModule4.Table _ judge. Open;
DataModule4.Table _ judge. Active: = false;
DataModule4.Table _ judge. Active: = true;
End;

Procedure TDataModule4.Table _ readproAfterDelete (DataSet: TDataSet );
Begin
DataModule4.Table _ readpro. Close;
DataModule4.Table _ readpro. Open;
DataModule4.Table _ readpro. Active: = false;
DataModule4.Table _ readpro. Active: = true;
End;

Procedure TDataModule4.Table _ procedureAfterDelete (DataSet: TDataSet );
Begin
DataModule4.Table _ procedure. Close;
DataModule4.Table _ procedure. Open;
DataModule4.Table _ procedure. Active: = false;
DataModule4.Table _ procedure. Active: = true;
End;

Procedure TDataModule4.Table _ shijuanBeforeDelete (DataSet: TDataSet );
Begin
Definepaperform. updatejno: = 0;
Definepaperform. updatejno: = table_shijuan ['jno'];
End;

End.

The above is the unit4 code, please take a look

Unit4 is a database connection module.

DataModule4.Table _ choose. Close; // The first set
DataModule4.Table _ choose. Open;
DataModule4.Table _ choose. Active: = false; // second set
DataModule4.Table _ choose. Active: = true;
Just use a set of code like this. Delete another set

I deleted it. It's useless. It's still a problem.

I deleted it. It's useless. It's still a problem.
========================================================== ================================
I mean, some of them are redundant statements. Your problem is that the DataSet was not opened and the operation was performed. You can trace the debugging to see the statement where the error occurs.

Newshijuanhao: = DataModule4.Table _ shijuan. FieldValues ['jno'] + 1;
That is, this row has an error.
In unit10, how can I modify it?

I guess the last sentence is wrong. The table is not opened. In DataModule4.Table _ shijuan. last; add DataModule4.Table _ shijuan. active: = True; try it. If the error persists, it indicates that the field name or field type is incorrect or the field value is null.

Thank you! The problem is solved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.