procedure ChangeFieldValue(RVData: TCustomRVData;
const s: String);
var ParaNo, StyleNo, Tag: Integer;
sl: TStringList;
i, Cnt: Integer;
begin
[color=red]RVData := RVData.GetRVData;[/color]
sl := GetStringListFromString(s);
if sl.Count<X_Arrcount then
Cnt := sl.Count
else
Cnt := X_Arrcount;
for i := 1 to Cnt do
RVData.SetItemText(aOrg[i], sl[i-1]);
if Cnt<X_Arrcount then begin // was "if sl.Count>Cnt then begin"
for i := X_Arrcount downto Cnt+1 do
RVData.DeleteItems(aOrg[i], 1)
end
else
if sl.Count>Cnt then begin
StyleNo := RVData.GetItemStyle(aOrg[X_Arrcount]);
ParaNo := RVData.[color=red]GetItemPara[/color](aOrg[X_Arrcount]);
Tag := RVData.GetItemTag(aOrg[X_Arrcount]);
for i := Cnt to sl.Count-1 do
RVInsertString(RVData, aOrg[X_Arrcount]+1, sl[i], StyleNo, ParaNo, Integer(StrNew(PChar(Tag))));
end;
sl.Free;
end;
2) This operation is not an editing operation, so call srv.RichViewEdit.ClearUndo after it.
3) Move caret to the beginning of the document before changing field value:
with srv.RichViewEdit do
SetSelectionBounds(0, GetOffsBeforeItem(0), 0, GetOffsBeforeItem(0));
if GetFieldLocation2(...) then
ChangeFieldValue(...);
srv.Format;
procedure ChangeFieldValue(RVData: TCustomRVData;
const s: String);
var ParaNo, StyleNo, Tag: Integer;
sl: TStringList;
i, Cnt: Integer;
begin
[color=red]RVData := RVData.GetRVData;[/color]
sl := GetStringListFromString(s);
if sl.Count<X_Arrcount then
Cnt := sl.Count
else
Cnt := X_Arrcount;
for i := 1 to Cnt do
RVData.SetItemText(aOrg[i], sl[i-1]);
if Cnt<X_Arrcount then begin // was "if sl.Count>Cnt then begin"
for i := X_Arrcount downto Cnt+1 do
RVData.DeleteItems(aOrg[i], 1)
end
else
if sl.Count>Cnt then begin
StyleNo := RVData.GetItemStyle(aOrg[X_Arrcount]);
ParaNo := RVData.[color=red]GetItemPara[/color](aOrg[X_Arrcount]);
Tag := RVData.GetItemTag(aOrg[X_Arrcount]);
for i := Cnt to sl.Count-1 do
RVInsertString(RVData, aOrg[X_Arrcount]+1, sl[i], StyleNo, ParaNo, Integer(StrNew(PChar(Tag))));
end;
sl.Free;
end;
2) This operation is not an editing operation, so call srv.RichViewEdit.ClearUndo after it.
3) Move caret to the beginning of the document before changing field value:
with srv.RichViewEdit do
SetSelectionBounds(0, GetOffsBeforeItem(0), 0, GetOffsBeforeItem(0));
if GetFieldLocation2(...) then
ChangeFieldValue(...);
srv.Format;
Dear Sergey Tkachenko,
Thank you for your help very much!
Do your mean that I modify my read button's click code is like this.
//----add by shao 2010-10-27--((
with srv.RichViewEdit do
SetSelectionBounds(0, GetOffsBeforeItem(0), 0, GetOffsBeforeItem(0));
//----add by shao 2010-10-27--)) //--modified as your suggestion 3
if GetFieldLocation2(Srv.RichViewEdit.RVData, 'eName15', RVData, ItemNo, ItemNoStr) then
ChangeFieldValue(RVData, X_result); //--modified as your suggestion 1
srv.RichViewEdit.ClearUndo; //--modified as your suggestion 2
srv.Format;
Is it that you let me do?
I test my program as above modification.It's run ok.
//----add by shao 2010-10-27--((
with srv.RichViewEdit do
SetSelectionBounds(0, GetOffsBeforeItem(0), 0, GetOffsBeforeItem(0));
//----add by shao 2010-10-27--)) //--modified as your suggestion 3
if GetFieldLocation2(Srv.RichViewEdit.RVData, 'eName15', RVData, ItemNo, ItemNoStr) then
ChangeFieldValue(RVData, X_result); //--modified as your suggestion 1
srv.RichViewEdit.ClearUndo; //--modified as your suggestion 2
srv.Format;
Yes
2) About wrong order of lines, one more fix is required:
procedure ChangeFieldValue(RVData: TCustomRVData;
const s: String);
var ParaNo, StyleNo, Tag: Integer;
sl: TStringList;
i, Cnt: Integer;
begin
RVData := RVData.GetRVData;
sl := GetStringListFromString(s);
if sl.Count<X_Arrcount then
Cnt := sl.Count
else
Cnt := X_Arrcount;
for i := 1 to Cnt do
RVData.SetItemText(aOrg[i], sl[i-1]);
if Cnt<X_Arrcount then begin // was "if sl.Count>Cnt then begin"
for i := X_Arrcount downto Cnt+1 do
RVData.DeleteItems(aOrg[i], 1)
end
else
if sl.Count>Cnt then begin
StyleNo := RVData.GetItemStyle(aOrg[X_Arrcount]);
ParaNo := RVData.GetItemPara(aOrg[X_Arrcount]);
Tag := RVData.GetItemTag(aOrg[X_Arrcount]);
for i := Cnt to sl.Count-1 do
RVInsertString(RVData, aOrg[X_Arrcount]+1[color=red]+i-Cnt[/color], sl[i], StyleNo, ParaNo, Integer(StrNew(PChar(Tag))));
end;
sl.Free;
end;