我做了一个基本的维护界面,其中用到了LabeledEdit1 控件,来实现比如2004020101这样的一个序号,不知道下面的代码如何才能在增加、保存能实现在labelededit1这个控件中
var i :integer
if i<10 then
str=FormatDateTime('yyyymmdd', Now)+'0'+inttostr(i)
else
str=FormatDateTime('yyyymmdd', Now)+inttostr(i)我是这样写的但是不行?求各位给指点!否则小弟只有洒泪
和您永别!!
procedure Truanjianfm.btnSaveClick(Sender: TObject);
var
i :integer
begin
if dbcombobox1.Text =''then
begin
showmessage('科室不能为空');
exit;
end;
if (FState = '1') or (FState = '2') then
begin
fmMain.adoconnection1.BeginTrans ;
try
ADOTable1.AfterScroll := nil;
if FState = '1' then
adotable1.Insert
else
ADOTable1.Edit;
if i<10 then
str=FormatDateTime('yyyymmdd', Now)+'0'+inttostr(i)
else
str=FormatDateTime('yyyymmdd', Now)+inttostr(i)
adotable1.FieldByName('apploffice').AsString := str ;
adotable1.FieldByName('phone').AsString := ledPhone.Text;
adotable1.FieldByName('time').AsDateTime := dtpTime.Date ;
adotable1.FieldByName('appliction').AsString := ledApplyPerson.Text ;
adotable1.FieldByName('principal').AsString := ledChargePerson.Text ;
adotable1.FieldByName('item').AsString := dbcombobox3.Text ;
adotable1.FieldByName('id').AsString := ledid.Text;
adotable1.FieldByName('paname').AsString := ledPatient.Text ;
adotable1.FieldByName('number').AsString := ledNumber.Text ;
adotable1.FieldByName('charger').AsString := dbcombobox4.Text ;
adotable1.FieldByName('mender').AsString := dbcombobox2.Text;
adotable1.FieldByName('re').AsString := ledReMark.Text ;
ADOTable1.Post ;
fmMain.adoconnection1.CommitTrans ;
except
ADOTable1.Cancel;
fmMain.adoconnection1.RollbackTrans ;
end;
end;
ADOTable1.AfterScroll := ADOTable1AfterScroll;
FState := '0';
SetButtonState;
DisplayRecord;
end;
var i :integer
if i<10 then
str=FormatDateTime('yyyymmdd', Now)+'0'+inttostr(i)
else
str=FormatDateTime('yyyymmdd', Now)+inttostr(i)我是这样写的但是不行?求各位给指点!否则小弟只有洒泪
和您永别!!
procedure Truanjianfm.btnSaveClick(Sender: TObject);
var
i :integer
begin
if dbcombobox1.Text =''then
begin
showmessage('科室不能为空');
exit;
end;
if (FState = '1') or (FState = '2') then
begin
fmMain.adoconnection1.BeginTrans ;
try
ADOTable1.AfterScroll := nil;
if FState = '1' then
adotable1.Insert
else
ADOTable1.Edit;
if i<10 then
str=FormatDateTime('yyyymmdd', Now)+'0'+inttostr(i)
else
str=FormatDateTime('yyyymmdd', Now)+inttostr(i)
adotable1.FieldByName('apploffice').AsString := str ;
adotable1.FieldByName('phone').AsString := ledPhone.Text;
adotable1.FieldByName('time').AsDateTime := dtpTime.Date ;
adotable1.FieldByName('appliction').AsString := ledApplyPerson.Text ;
adotable1.FieldByName('principal').AsString := ledChargePerson.Text ;
adotable1.FieldByName('item').AsString := dbcombobox3.Text ;
adotable1.FieldByName('id').AsString := ledid.Text;
adotable1.FieldByName('paname').AsString := ledPatient.Text ;
adotable1.FieldByName('number').AsString := ledNumber.Text ;
adotable1.FieldByName('charger').AsString := dbcombobox4.Text ;
adotable1.FieldByName('mender').AsString := dbcombobox2.Text;
adotable1.FieldByName('re').AsString := ledReMark.Text ;
ADOTable1.Post ;
fmMain.adoconnection1.CommitTrans ;
except
ADOTable1.Cancel;
fmMain.adoconnection1.RollbackTrans ;
end;
end;
ADOTable1.AfterScroll := ADOTable1AfterScroll;
FState := '0';
SetButtonState;
DisplayRecord;
end;
timecode=stringreplace(datetostr(now),'-','',[rfReplaceAll])+inttostr(inc(i));
if i<10 then
str=FormatDateTime('yyyymmdd', Now)+'0'+inttostr(i)
else
str=FormatDateTime('yyyymmdd', Now)+inttostr(i)
================
上面是你的代码
其实根本不用判断什么i是否大于或小于10的似乎你的本意只是想在前面补0
可以用Format()来实现的
var
i:Integer;
begin
i:=1;
Showmessage(Format('%.2d',i); //此时出现的将会是01
end;
放到程序开始的地方
假设i是递增的
str=stringreplace(datetostr(now),'-','',[rfReplaceAll])+Format('%.2d',i);adotable1.FieldByName('apploffice').AsString := str ;
...
没必要用StringReplace()函数来替换日期值里的'-'符号的
直接用FormatDateTime('yyyymmdd',now)出来的值就是没有'-'符号的