23-06-2009, 08:20 PM
هناك طريقه (و لكل شيخ طريقته :d )
بما انك تستخدم آليه اضافة رقم مكون من 4 خانات مسبوق بالحرفين BK
بما انك تستخدم آليه اضافة رقم مكون من 4 خانات مسبوق بالحرفين BK
كود :
{*********}
if not (DataSet.State = dsInsert) then Exit;
DataSet.FieldByName('BookID').AsString := 'BK'+
Format('%0.4d',[GetMax+1]);
{*********}
function GetMax : Integer;
var
S : String;
Max, CValue : Integer;
begin
With Table do
begin
First;
Max := 1;
While not EOF do
begin
S := Copy(Table.FieldByName('BookID').AsString,3,4);
CValue := StrToInt(S);
if CValue > Max then Max := CValue;
Next;
end;
end;
Result := Max;
end;
