受不了了,请大家帮忙,怎么可能出现这种错误?(50分)

  • 主题发起人 主题发起人 vickymade
  • 开始时间 开始时间
V

vickymade

Unregistered / Unconfirmed
GUEST, unregistred user!
原程序如下:

unit BaseDataInput;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls;

type
TfrmBaseDataInputForm = class(TForm)
NumberLabel: TLabel;
NameLabel: TLabel;
GenerLabel: TLabel;
BirthdayLabel: TLabel;
Edu_LevelLabel: TLabel;
AcademyLabel: TLabel;
GraduateDateLabel: TLabel;
EnterpriseLabel: TLabel;
DapartmentLabel: TLabel;
EnterPropertyLabel: TLabel;
TaskDateLabel: TLabel;
DutyLabel: TLabel;
EngageDateLabel: TLabel;
ShoulderTimeLabel: TLabel;
CompetencyLabel: TLabel;
SpecialtyLabel: TLabel;
SpecialityLabel: TLabel;
SeriesLabel: TLabel;
Foreign_LanguageAchievementLabel: TLabel;
ComputerAchievementLabel: TLabel;
NumberEdit: TEdit;
NameEdit: TEdit;
GenerComboBox: TComboBox;
Edu_LevelComboBox: TComboBox;
AcademyEdit: TEdit;
DapartmentComboBox: TComboBox;
EnterPropertyComboBox: TComboBox;
DutyComboBox: TComboBox;
ShoulderTimeEdit: TEdit;
EnterpriseComboBox: TComboBox;
CompetencyComboBox: TComboBox;
SpecialtyComboBox: TComboBox;
SpecialityComboBox: TComboBox;
SeriesComboBox: TComboBox;
Foreign_LanguageAchievementComboBox: TComboBox;
ComputerAchievementComboBox: TComboBox;
Button1: TButton;
BirthdayDateTimePicker: TDateTimePicker;
GraduateDateDateTimePicker: TDateTimePicker;
TaskDateDateTimePicker: TDateTimePicker;
EngageDateTimePicker: TDateTimePicker;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmBaseDataInputForm: TfrmBaseDataInputForm;
I:Integer=0;
implementation
uses MainForm,BaseDataInputDataModule;

{$R *.dfm}

procedure TfrmBaseDataInputForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action:=cafree;
end;

procedure TfrmBaseDataInputForm.FormDestroy(Sender: TObject);
begin
frmBaseDataInputForm:=nil;
end;

procedure TfrmBaseDataInputForm.Button1Click(Sender: TObject);
begin
BaseDataDM.DataInputADOTable.Open();
with BaseDataDM.DataInputADOTable do
begin
try

Open();
Edit();
Append();

//设置在各个Edit中的输入不能为空
//--------------------------------------------------------------------------
if
(
(NameEdit.Text<>'') and (AcademyEdit.Text<>'') and (ShoulderTimeEdit.Text<>'')
)
then
begin
//--------------------------------------------------------------------------

//--------------------------------------------------------------------------
//设置个输入项的逻辑值不能不合理
//--------------------------------------------------------------------------

if NOT((StrtoInt(ShoulderTimeEdit.Text)<0) and (StrtoInt(ShoulderTimeEdit.Text)>100))
then
begin
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------

//尝试POST各项的值
//--------------------------------------------------------------------------
if CanModify then
begin

{ 错误就出现在这里 }
//FieldByName('InputNumber').AsString:=IntToStr(Inc(I));
{ 提示:[Error]BaseDataInput.pas[122]:There is no overloaded version of 'IntToStr' that can be called with thers arguments }



FieldByName('InputName').AsString:=NameEdit.Text;
FieldByName('InputGener').AsString:=GenerComboBox.Text;
FieldByName('InputBirthday').AsDateTime:=BirthdayDateTimePicker.Date;
FieldByName('InputEdu_Level').AsString:=Edu_LevelComboBox.Text;
FieldByName('InputAcademy').AsString:=AcademyEdit.Text;
FieldByName('InputGraduateDate').AsDateTime:=GraduateDateDateTimePicker.Date;
FieldByName('InputEnterPrise').AsString:=EnterpriseComboBox.Text;
FieldByName('InputDapartment').AsString:=DapartmentComboBox.Text;
FieldByName('InputEnterProperty').AsString:=EnterPropertyComboBox.Text;
FieldByName('InputTaskDate').AsDateTime:=TaskDateDateTimePicker.Date;
FieldByName('InputDuty').AsString:=DutyComboBox.Text;
FieldByName('InputEngageDate').AsDateTime:=EngageDateTimePicker.Date;
FieldByName('InputOccupyTime').AsString:=ShoulderTimeEdit.Text;
FieldByName('InputCompetency').AsString:=CompetencyComboBox.Text;
FieldByName('InputSpeciality').AsString:=SpecialtyComboBox.Text;
FieldByName('InputSort').AsString:=SeriesComboBox.Text;
FieldByName('InputSeries').AsString:=SeriesComboBox.Text;
FieldByName('Foreign_LanguageAchievement').AsString:=Foreign_LanguageAchievementComboBox.Text;
FieldByName('ComputerAchievement').AsString:=ComputerAchievementComboBox.Text;
FieldByName('IsPassPrejudication').AsString:='N';

Post();
Close();
end;
end;
end;
finally
BaseDataDM.DataInputADOTable.Cancel();
BaseDataDM.DataInputADOTable.Close();
end;
end;

end;

end.


我在unit BaseDataInputDataModule中有如下操作:
procedure TBaseDataDM.DataInputADOTableAfterPost(DataSet: TDataSet);
begin
// BirthdayDateTimePicker.Date:=
with frmBaseDataInputForm do
begin
NumberEdit.Text:='';
NameEdit.Text:='';
GenerComboBox.Text:='';

Edu_LevelComboBox.Text:='';
AcademyEdit.Text:='';

EnterpriseComboBox.Text:='';
DapartmentComboBox.Text:='';
EnterPropertyComboBox.Text:='';

DutyComboBox.Text:='';

CompetencyComboBox.Text:='';
SpecialtyComboBox.Text:='';
SpecialityComboBox.Text:='';
SeriesComboBox.Text:='';
Foreign_LanguageAchievementComboBox.Text:='';
ComputerAchievementComboBox.Text:='';
end;
end;

procedure TBaseDataDM.DataInputADOTableAfterOpen(DataSet: TDataSet);
begin
if not(DataInputADOTable.Bof) then
begin
with DataInputADOTable do
//移动指针指向前一条记录将编号赋给变量I,然后将记录指针回原记录。
begin
Open();
Last();
//Prior();
I:=StrtoInt(Trim(FieldByName('InputNumber').AsString));
//Next();
Edit()
end;
end
else
with DataInputADOTable do
begin
//FieldByName('InputNumber').AsString:=IntToStr(Inc(I));
I:=1;
Edit();
end;
end;


请大家指点。
 
把出错那句改下,inc(i)分开写
inc(i);
FieldByName('InputNumber').AsString:=IntToStr(I);

inc是过程,无返回值
 
它提示的是不能调用IntToStr呀!跟Inc也没有关系呀。
 
FieldByName('InputNumber').AsString:=IntToStr(Inc(I));
改为:
Inc(I);
FieldByName('InputNumber').AsString:=IntToStr(I);
错误是指 IntToStr 函数的参数不对,参数内不能有Inc(I)

 
可是,在第二次Post的时候,报错。提示:
Project AssessProject.exe raised exception class EOleException with message '违反了PRIMARY KEY 约束'Pk_BasicDeclare_Table'.
不能再对象‘BasicDeclare_Table’中插入重复键。’。Process stopped Use Step to Run or Run to continue.这又是为什么呢?
 
那是因为你在BasicDeclare_Table中插入的主键值与已经存在的主键值重复.
 
怎么解决呢?
 
在插入前检查当前插入记录是否符合数据库完整性约束。
比如可以在post前:
 CheckSQL.sql.text:="select PrimaryKey from tablename where PrimaryKey=:PrimaryKey";
CheckSQL.ParambyName("PrimaryKey").Value:= FieldByName(....).Value;
CheckSQL.Open;
if CheckSQL.RecordCount>1 then
begin
ShowMessage("插入的记录不合要求");
CheckSQL.Close
end
else
begin
post;
.................
end;;
 
但是,我的程序为什么会出现完整性约束条件的错误呢?
 
后退
顶部