这样可以吗?type Tmyint64=record hi:int64; lo:int64; end; var myint64:Tmyint64;procedure myint64inc(val:Tmyint64); begin if val.lo=high(int64) then inc(val.hi) else inc(val.lo); end; procedure TForm1.Button1Click(Sender: TObject); var str:string; begin myint64.lo:=1234567;//测试 myint64.hi:=4567788; myint64inc(myint64); str:=inttostr(myint64.hi)+inttostr(myint64.lo); showmessage(str); end;
type TIntString = array [0..10] of Char;procedure IncInt(var V: TIntString); var I: ShortInt; begin I := High(TIntString); while not (V[I] in ['0'..'9']) do Dec(I); while V[I] = '9' do begin V[I] := '0'; Dec(I); if I < 0 then break; end; if I >= 0 then Inc(V[I]); end;procedure TForm1.Button1Click(Sender: TObject); procedure DoIt(var V: TIntString); begin IncInt(V); Memo1.Lines.Add(V); end;var V: TIntString; begin V := '9000000001'; DoIt(V); V := '9000000008'; DoIt(V); V := '9999999998'; DoIt(V); DoIt(V); DoIt(V); end;
const initLen=10;
a:array of char;
SetLength(a,initLen);
a[1]:='1'
……
……
……
SetLength(a,initLen+N);//N可以自己去设置
这是动态字符数组,不是我需要的吧。
需要实现的是类似自增字段(autoinc)的功能,但是因为该数字比较大,所以用字符串储存。
如:
90000000000000000000001
90000000000000000000002
90000000000000000000003
90000000000000000000004
90000000000000000000005
90000000000000000000006
...................
这样的序列。
Tmyint64=record
hi:int64;
lo:int64;
end;
var
myint64:Tmyint64;procedure myint64inc(val:Tmyint64);
begin
if val.lo=high(int64) then
inc(val.hi)
else
inc(val.lo);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
begin
myint64.lo:=1234567;//测试
myint64.hi:=4567788;
myint64inc(myint64);
str:=inttostr(myint64.hi)+inttostr(myint64.lo);
showmessage(str);
end;
TIntString = array [0..10] of Char;procedure IncInt(var V: TIntString);
var
I: ShortInt;
begin
I := High(TIntString);
while not (V[I] in ['0'..'9']) do Dec(I); while V[I] = '9' do
begin
V[I] := '0';
Dec(I);
if I < 0 then break;
end;
if I >= 0 then
Inc(V[I]);
end;procedure TForm1.Button1Click(Sender: TObject); procedure DoIt(var V: TIntString);
begin
IncInt(V);
Memo1.Lines.Add(V);
end;var
V: TIntString;
begin
V := '9000000001';
DoIt(V);
V := '9000000008';
DoIt(V);
V := '9999999998';
DoIt(V);
DoIt(V);
DoIt(V);
end;
自己再写DecInt函数。