there is a table : SysCode
there is no data in SysCode initially
if (not CheckIfExistedInSysCode('MachNameMapTob','*',0)) then
begin
InsertSysCodeKind('MachNameMapTob','Map Data');
end;
var existed := CheckIfExistedInSysCode('MachNameMapTob','*',0);
if(existed) then
ShowMessage('@@ * EXISTED!!')
else
ShowMessage('* NOt existed !!');
first ,i run the program
there is no data existed then it will 'InsertSysCodeKind'
there has data inside SysCode
but when run ' var existed := CheckIfExistedInSysCode('MachNameMapTob','*',0);'
i will get error
then i must stop the program
but if i run the program again
there has data inside SysCode
then it run ' var existed := CheckIfExistedInSysCode('MachNameMapTob','*',0);'
no error shown
why ?
You are trying to insert an Integer id with value 0. That is a "no value" for Aurelius. If you really want to allow 0 as a valid id value, then use IdUnsavedValue to indicate a value that will mean "no id":
Ok, I see now that the problem in your code is that SysCode object is destroyed. If you run everything a second time, the object is retrieved. The reason is that you are destroying the object after saving, and you should not do it, because Aurelius manager will destroy it already:
try
with sysCode do
begin
CodeType := inCodeType;
CodeTypNM := inCodeTypNM;
CodeInx := 0;
CodeNo := '*';
CodeNM := '';
CodeDesc := '';
NotShow := 0;
CreateDate := Now();
CreateUser := 'cova';
UpdateDate := CreateDate;
UpdateUser := CreateUser;
end;
Form1.arlsmngr.Save(sysCode);
Result := True;
message := 'SUCCESS';
finally
// DON'T DO THIS
// FreeAndNil(sysCode);
end;
A better approach is doing it this way:
var sysCode := TSysCode.Create;
Form1.arlsmngr.ObjManager.AddOwnership(sysCode);
var message := 'fail';
with sysCode do
begin
CodeType := inCodeType;
CodeTypNM := inCodeTypNM;
CodeInx := 0;
CodeNo := '*';
CodeNM := '';
CodeDesc := '';
NotShow := 0;
CreateDate := Now();
CreateUser := 'cova';
UpdateDate := CreateDate;
UpdateUser := CreateUser;
end;
Form1.arlsmngr.Save(sysCode);
All that process is explained in details in the manual. Please check: