好,我就贴一个过程:sgd是stringgrid
procedure tfrmMdiChild.UnDo;
var
id,operation:string;
i,j,k:integer;
value:array of variant;
begin
if onlyread then
exit;
if lbxoperation.Items.Count<>0 then
begin
operation:=copy(lbxoperation.Items[lbxoperation.Items.Count-1],1,1);
if operation<>'-' then
begin
sgd.Row:=strtoint(copy(LbxOperation.Items[lbxoperation.Items.Count-1],2,pos(';',LbxOperation.Items[lbxoperation.Items.Count-1])-2));
if operation='@' then
begin
id:=copy(trim(LbxOperation.Items[lbxoperation.Items.Count-1]),pos(';',trim(LbxOperation.Items[lbxoperation.Items.Count-1]))+1,length(trim(LbxOperation.Items[lbxoperation.Items.Count-1]))-pos(';',trim(LbxOperation.Items[lbxoperation.Items.Count-1])));
k:=getsubstrnum(',',GetPrimaryKey);
setlength(value,k);
for i:=1 to kdo
value[i-1]:=StrToOther(getstring(',',GetPrimaryKey,i),getstring(chr(compart),id,i));
if cds.Locate(SubstrReplace(GetPrimaryKey,',',';'),vararrayof(value),[]) then
begin
for i:=1 to sgd.ColCount-1do
sgd.Cells[i,sgd.row]:=(VarToStr(cds[lbxfieldname.Items[i-1]]));
end;
end;
if operation='+' then
deleterow;
end
else
begin
ID:=copy(trim(LbxOperation.Items[lbxoperation.Items.Count-1]),2,length(trim(LbxOperation.Items[lbxoperation.Items.Count-1]))-1);
lbxid.items.add(id);
k:=getsubstrnum(',',GetPrimaryKey);
setlength(value,k);
for i:=1 to kdo
value[i-1]:=StrToOther(getstring(',',GetPrimaryKey,i),getstring(chr(compart),id,i));
if cds.Locate(SubstrReplace(GetPrimaryKey,',',';'),vararrayof(value),[]) then
begin
sgd.rowcount:=sgd.rowcount+1;
sgd.Rows[sgd.rowcount-1].Add(inttostr(sgd.RowCount-1));
for i:=1 to sgd.ColCount-1do
sgd.Cells[i,sgd.RowCount-1]:=(VarToStr(cds[lbxfieldname.Items[i-1]]));
sgd.Row:=sgd.rowcount-1;
end;
// lbxid.items.add(id);
end;
if operation<>'+' then
lbxoperation.Items.Delete(lbxoperation.Items.Count-1);
sgd.Refresh;
end;
if Assigned(OnCell) then
OnCell(SGD);
changememolist(sgd.Selection.Bottom);
end;