gpt4 book ai didi

delphi - 字段 'Invoice_Date' 无法修改

转载 作者:行者123 更新时间:2023-12-03 18:33:09 26 4
gpt4 key购买 nike

我有以下 ms access 2003 表:

Invoice_Master
(
Invoice_Id Autonumber,
Customer_Id integer,
Invoice_Date Date/Time not null,
.
.
.
);

和以下代码(Delphi 7)
procedure TfmInvoiceMaster.adoMasterEditNewRecord(DataSet: TDataSet);
begin
inherited;
adoMasterEditInvoice_Date.AsDateTime := Date;
end;

当我尝试添加新记录时,我以异常错误 sys 结束:

Field 'Invoice_Date' cannot be modified.



请问有什么问题

最佳答案

你这样做是错的。 :)

您应该使用 AfterEdit事件代替。来自 TDataSet.AfterEdit 上的帮助文件:

Write an AfterEdit event handler to take specific action immediately after dataset enters edit mode. AfterEdit is called by Edit after it enables editing of a record, recalculates calculated fields, and calls the data event handler to process a record change.



像这样使用它:
procedure TfmInvoiceMaster.adoMasterAfterEdit(DataSet: TDataSet);
begin
// No inherited call! This is an event handler, not an overridden method
adoMasterEditInvoice_Date.AsDateTime := Date;
end;

但是,从您的文本中,您似乎想要在插入记录时执行此操作,而不是进行编辑(“当我尝试添加新记录时,我以异常错误 sys:”结束)。如果是这种情况,请使用 AfterInsert完全相同的方式:
procedure TfmInvoiceMaster.adoMasterAfterInsert(DataSet: TDataSet);
begin
// No inherited call! This is an event handler, not an overridden method
adoMasterEditInvoice_Date.AsDateTime := Date;
end;

关于delphi - 字段 'Invoice_Date' 无法修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10000515/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com