应该不是你说的这种情况吧,我的代码如下,但我只要把nowname : TContextCurrent;定义在procedure TJHDDXX.DataSetJHDDSJJFieldChange(DataSet: TDataSet; Field: TDataField);里面就没有错了,我在前面定义的对像的变量,也在方法里面创建了才使用啊
implementation
var
nowname : TContextCurrent;
procedure TJHDDXX.DataSetJHDDSJJFieldChange(DataSet: TDataSet; Field: TDataField);
begin
nowname := TContextCurrent.Create(self.Context);
try
if (Field <> nil) and (Field.FieldName = 'YJSP') then
begin
DataSetJHDDSJJ.FieldByName['YJSPR'].AsString := nowname.Operator.DisplayName;
end;
if (Field <> nil) and (Field.FieldName = 'EJSP') then
begin
DataSetJHDDSJJ.FieldByName['EJSPR'].AsString := nowname.Operator.DisplayName;
end;
if (Field <> nil) and (Field.FieldName = 'CWSY') then
begin
DataSetJHDDSJJ.FieldByName['CWSYR'].AsString := nowname.Operator.DisplayName;
end;
finally
nowname.Free;
end;
end; |