Page 3 of 3

Posted: Mon Oct 25, 2010 12:44 am
by srvsxf
Sergey Tkachenko wrote:This link does not work (it requires me to log in?)
I'm sorry that I have not test it before.

Please try this link.(http://www.cnblogs.com/mikalshao/archiv ... 60080.html)

click the ¡¾Delphi Program¡¿Link.

If you have also other problem, please tell me.

Thanks

Posted: Mon Oct 25, 2010 12:52 am
by srvsxf
I test it.

If you use "right" click to save ,it's not successful.

The best is to use your download software to download it.

I test it with download software, it's ok.

Posted: Tue Oct 26, 2010 6:43 pm
by Sergey Tkachenko
Corrections in the code:
1) Modify ChangeFieldValue:

Code: Select all

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:

Code: Select all

  with srv.RichViewEdit do
    SetSelectionBounds(0, GetOffsBeforeItem(0), 0, GetOffsBeforeItem(0));
  if GetFieldLocation2(...) then
    ChangeFieldValue(...);
  srv.Format;

Posted: Wed Oct 27, 2010 12:51 am
by srvsxf
Sergey Tkachenko wrote:Corrections in the code:
1) Modify ChangeFieldValue:

Code: Select all

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:

Code: Select all

  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.

Code: Select all

 //----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.

Thanks a lot.

Posted: Wed Oct 27, 2010 1:31 am
by srvsxf
Dear Sergey Tkachenko,

The program run ok.But when I test it,I found a new problem.

My operate steps is as below.
1)I input the content on the tag "eName15".
http://www.cnblogs.com/mikalshao/galler ... 95383.html
2)I click "save" button to save it to the "X_result".
http://www.cnblogs.com/mikalshao/galler ... 95384.html
3)I clear the "eName15" tag's content.
(the detail operator is delete the other "eName15" tag,only left one)
http://www.cnblogs.com/mikalshao/galler ... 95385.html
4)I click "read" button to read the "X_result" to the "eName15" tag.
http://www.cnblogs.com/mikalshao/galler ... 95386.html
(then the order is correct.)
5)I click the "OK" button. The "eName15" tag's content is as below.
http://www.cnblogs.com/mikalshao/galler ... 95387.html

The "eName15" tag's content order is not as I input.
http://www.cnblogs.com/mikalshao/galler ... 95383.html

6)I click the read button again.The "eName15" tag is as below.
http://www.cnblogs.com/mikalshao/galler ... 95389.html

It's orde is correct. again.

why?

Please help.

Thanks

Posted: Wed Oct 27, 2010 12:58 pm
by Sergey Tkachenko
1)
srvsxf wrote:Do your mean that I modify my read button's click code is like this.

Code: Select all

 //----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:

Code: Select all

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;

Posted: Thu Oct 28, 2010 12:55 am
by srvsxf
Dear Sergey Tkachenko,

Thank you very much!

I tested my program as your suggestion.

My program run successful.

My problems are solved .

Thanks a lot. :D