How the Cursor move in the Tags of TSrichViewEdit ?

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

Sergey Tkachenko,

I searched the two funcitons.
I create my funcitons base on them.

The detail is as below.

Code: Select all

procedure TForm1.bSaveClick(Sender: TObject);
var s: String;
begin
s := trim(GetFieldValue2(srv.RichViewEdit, 'eName5'));
showmessage('»бХпјЗВјЎѕ'+s+'Ўї±ЈґжіЙ№¦ЈЎ');
end;

Code: Select all

function GetFieldValue2(rv: TCustomRichView; const field: String): String;
var ItemNo: Integer;
    RVData: TCustomRVData;
    ItemNoStr :string;
    i:integer;
begin
  Result:='';
  if GetFieldLocation2(rv.RVData, field, RVData, ItemNo,ItemNoStr) then begin
      for i:=1 to X_Arrcount do
      begin
        Result :=Result+ RVData.GetRVData.GetItemText(aOrg[i]);
      end;
    end
  else
    Result := 'error';
end;

Code: Select all

function GetFieldLocation2(RootRVData: TCustomRVData; const field: String;
                           var RVData: TCustomRVData;
                           var ItemNo: Integer;
                           var strItemNo:string): Boolean;
var i,j,r,c: Integer;
    table: TRVTableItemInfo;
begin
  X_Arrcount:=0;
  Result := False;
  strItemNo:='';
  for i := 0 to RootRVData.ItemCount-1 do
    if RootRVData.GetItemStyle(i)=rvsTable then begin
      table := TRVTableItemInfo(RootRVData.GetItem(i));
      for r := 0 to table.Rows.Count-1 do
        for c := 0 to table.Rows[r].Count-1 do
          if table.Cells[r,c]<>nil then begin
             for j:=0 to table.Cells[r,c].GetRVData.ItemCount-1 do
             begin
                if PChar(table.Cells[r,c].GetRVData.GetItemTag(j)) = field then begin
                inc(X_Arrcount);
                ItemNo := j;
                aOrg[X_Arrcount]:=j;
                strItemNo:=strItemNo+inttostr(ItemNo)+',';
                RVData := table.Cells[r,c].GetRVData.GetSourceRVData;
                Result := True;
               // exit;
                end;
             end;
          end
      end;
  if Result then
  strItemNo:=copy(strItemNo,1,length(strItemNo)-1)
  else
   strItemNo:='xxx';
end;
I uses them can get the values of "eName5".

But another new problem ?

If I save the "eName5" tags's values as user's input format.
when the user read the data,how I read the data from database to the "eName5" tag as user input format?

I only create one "eName5" tag on the even of form create.
How I write the data to the "eName5" tag?

Please help me.

Thanks
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

Urgent!

Please help me!

Thanks!
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry for delay.

As I understand, you need to change text of the field.

1) Use the unit http://www.trichview.com/support/files/ ... tItems.zip
(the most probably, it will be included in the next versions of TRichView.
This unit has the function RVInsertString allowing to insert a single line of of text in the specified place of RVData.

2) Use the functions below

Code: Select all

function GetStringListFromString(const s: String): TStringList;
begin
  Result := TStringList.Create;
  Result.Text := s;
  { workaround - TStringList ignores the last cr lf }
  if (Length(s)>1) and
     (s[Length(s)-1]=#13) and (s[Length(s)]=#10) then
    Result.Add('');
  { end of workaround }
end;

procedure ChangeFieldValue(RVData: TCustomRVData
  const s: String);
var ParaNo, StyleNo, Tag: Integer;
    sl: TStringList;
    i, Cnt: Integer;
begin
  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 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.GetItemStyle(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;
How to use

Code: Select all

if GetFieldLocation2(rv.RVData, field, RVData, ItemNo, 'eName5') then 
  ChangeFieldValue(RVData, 'new value for eName5');
Sorry, this code was not tested properly, so if it has bugs, let me know.
Last edited by Sergey Tkachenko on Mon Oct 18, 2010 5:38 pm, edited 1 time in total.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I created these functions for you, but I HIGHLY recommend you to use one of demos from http://www.trichview.com/forums/viewtopic.php?t=8 as a basis, instead of these functions.
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

Sergey Tkachenko wrote:Sorry for delay.

As I understand, you need to change text of the field.

1) Use the unit http://www.trichview.com/support/files/ ... tItems.zip
(the most probably, it will be included in the next versions of TRichView.
This unit has the function RVInsertString allowing to insert a single line of of text in the specified place of RVData.

2) Use the functions below

Code: Select all

function GetStringListFromString(const s: String): TStringList;
begin
  Result := TStringList.Create;
  Result.Text := s;
  { workaround - TStringList ignores the last cr lf }
  if (Length(s)>1) and
     (s[Length(s)-1]=#13) and (s[Length(s)]=#10) then
    Result.Add('');
  { end of workaround }
end;

procedure ChangeFieldValue(RVData: TCustomRVData
  const s: String);
var ParaNo, StyleNo, Tag: Integer;
    sl: TStringList;
    i, Cnt: Integer;
begin
  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 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.GetItemStyle(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;
How to use

Code: Select all

if GetFieldLocation2(rv.RVData, field, RVData, ItemNo, 'eName5') then 
  ChangeFieldValue(RVData, 'new value for eName5');
Sorry, this code was not tested properly, so if it has bugs, let me know.
Thank you for your replay.

My sourcecode is an example.

My program has serval tags like "eName5".The "aOrg" and the Arrcount can change with the tag's name. So I think the the function can not apply my program.
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

Sergey Tkachenko wrote:I created these functions for you, but I HIGHLY recommend you to use one of demos from http://www.trichview.com/forums/viewtopic.php?t=8 as a basis, instead of these functions.
Thank you for your reply.

I'm sorry I can't be blind to the demo.

Here's my meaning's sourcecode.
1.create the talbe and the tags.
TForm1.FormCreate and the procedure prInitTable01;

Code: Select all

 procedure TForm1.FormCreate(Sender: TObject);
var r,c: Integer;
begin
  srv.RichViewEdit.Clear;
  prInitTable01;
end;

procedure TForm1.prInitTable01;
var r,c,m,n: Integer;
begin
  m:=2;
  n:=14;
  table1 := TRVTableItemInfo.CreateEx(m,n, srv.RichViewEdit.RVData);
  for r:=0 to m-1 do
  begin
    for c:=0 to n-1 do
    table1.Cells[r,c].Clear;
  end;
  table1.BorderWidth := 0;
  table1.CellBorderWidth := 0;
  table1.CellBorderStyle := rvtbColor;
  table1.CellBorderColor := clwhite;
  table1.BorderStyle := rvtbColor;

  with table1 do begin
    Cells[0,12].AddNL('ГЕХпєЕ',0,0);

    Cells[1,0].AddNL('РХГы',0,0);
    Cells[1,2].AddNL('РФ±р',0,0);
    Cells[1,4].AddNL('ДкБд',0,0);
    Cells[1,6].AddNL('їЖ±р',0,0);
    Cells[1,8].AddNL('ІЎКТ',0,0);
    Cells[1,10].AddNL('ґІєЕ',0,0);
    Cells[1,12].AddNL('ЧЎФєєЕ',0,0);

    //----РґИлTag
    Cells[0,13].Clear;
    Cells[0,13].AddNLTag('eName1',6,0,Integer(StrNew('eName1')));

    //Cells[0,13].AddTextBlockNLA('ssss',6,0,Integer(StrNew('eName1')));
    Cells[1,1].Clear;
    Cells[1,3].Clear;
    Cells[1,5].Clear;
    Cells[1,7].Clear;
    Cells[1,9].Clear;
    Cells[1,11].Clear;
    Cells[1,13].Clear;

    Cells[1,1].AddNLTag('eName2',6,0,Integer(StrNew('eName2')));
    Cells[1,3].AddNLTag('eName3',6,0,Integer(StrNew('eName3')));
    Cells[1,5].AddNLTag('eName4',6,0,Integer(StrNew('eName4')));
    Cells[1,7].AddNLTag('eName5',6,0,Integer(StrNew('eName5')));
    Cells[1,9].AddNLTag('eName6',6,0,Integer(StrNew('eName6')));
    Cells[1,11].AddNLTag('eName7',6,0,Integer(StrNew('eName7')));
    Cells[1,13].AddNLTag('eName8',6,0,Integer(StrNew('eName8')));
  end;
  srv.RichViewEdit.InsertItem('', table1);
end;
Run the my program,It's like this.
http://www.cnblogs.com/mikalshao/galler ... 95246.html
2.Save the user input content

Code: Select all

procedure TForm1.bSaveClick(Sender: TObject);
var s: String;
begin
  s := trim(GetFieldValue2(srv.RichViewEdit, 'eName5'));
  showmessage('»бХпјЗВјЎѕ'+s+'Ўї±ЈґжіЙ№¦ЈЎ');
  //--I save the data "S" to the database.
  //--The S ='1111'+'^'+'2222'+'^'+'3333'
end;

function GetFieldValue2(rv: TCustomRichView; const field: String): String;
var ItemNo: Integer;
    RVData: TCustomRVData;
    ItemNoStr :string;
    i:integer;
begin
  Result:='';
  if GetFieldLocation2(rv.RVData, field, RVData, ItemNo,ItemNoStr) then begin
      for i:=1 to X_Arrcount do
      begin
        Result :=Result+ RVData.GetRVData.GetItemText(aOrg[i]);
      end;
    end
  else
    Result := 'error';
end;

function GetFieldLocation2(RootRVData: TCustomRVData; const field: String;
                           var RVData: TCustomRVData;
                           var ItemNo: Integer;
                           var strItemNo:string): Boolean;
var i,j,r,c: Integer;
    table: TRVTableItemInfo;
begin
  X_Arrcount:=0;
  Result := False;
  strItemNo:='';
  for i := 0 to RootRVData.ItemCount-1 do
    if RootRVData.GetItemStyle(i)=rvsTable then begin
      table := TRVTableItemInfo(RootRVData.GetItem(i));
      for r := 0 to table.Rows.Count-1 do
        for c := 0 to table.Rows[r].Count-1 do
          if table.Cells[r,c]<>nil then begin
             for j:=0 to table.Cells[r,c].GetRVData.ItemCount-1 do
             begin
                if PChar(table.Cells[r,c].GetRVData.GetItemTag(j)) = field then begin
                inc(X_Arrcount);
                ItemNo := j;
                aOrg[X_Arrcount]:=j;
                strItemNo:=strItemNo+inttostr(ItemNo)+',';
                RVData := table.Cells[r,c].GetRVData.GetSourceRVData;
                Result := True;
               // exit;
                end;
             end;
          end
      end;
  if Result then
  strItemNo:=copy(strItemNo,1,length(strItemNo)-1)
  else
   strItemNo:='xxx';
end;

The user input the content like this.
http://www.cnblogs.com/mikalshao/galler ... 95247.html
then click the "save" button.My program is like this.
http://www.cnblogs.com/mikalshao/galler ... 95248.html
when I update the database,I will use "^" to differentiate them from the several "eName5" tags.

Code: Select all

procedure TForm1.bSaveClick(Sender: TObject);
var s: String;
begin
  s := trim(GetFieldValue2(srv.RichViewEdit, 'eName5'));
  showmessage('»бХпјЗВјЎѕ'+s+'Ўї±ЈґжіЙ№¦ЈЎ');
  //--I save the data "S" to the database.
  //--The S ='1111'+'^'+'2222'+'^'+'3333'
end;
3.when the user save to database ,My program is like this.
http://www.cnblogs.com/mikalshao/galler ... 95249.html
then they click the "Read" button .They Read to data from database to the richview again.
The format is they hope .The detail is as below.
http://www.cnblogs.com/mikalshao/galler ... 95250.html
how to realize?
Please help me.
Thanks
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

I'm meaning is that I hope when the user read the data again, the richview format as the user input before.
(when the user input ,they perhaps user "enter" key auto create serval "eName" tags.)

example:
when input:
1111
2222
3333

when read:

I hope :
1111
2222
3333

not like this:
111122223333

Thanks
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As I understand, you modified GetFieldValue2 so that it adds '^' between lines.

To change 'eName5' to multiline text:
1) Read field value from database (s = '111^222^333')
2) Change '^' to #13#10 (s = '111'#13#10'222'#13#10'333)
3) Call:

Code: Select all

if GetFieldLocation2(rv.RVData, field, RVData, ItemNo, 'eName5') then 
  ChangeFieldValue(RVData, s);
In this code, GetFieldLocation2 fills aOrg and X_Arrcount for 'eName5', and ChangeFieldValue uses these values to change visible text of 'eName5' field.
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

Sergey Tkachenko wrote:As I understand, you modified GetFieldValue2 so that it adds '^' between lines.

To change 'eName5' to multiline text:
1) Read field value from database (s = '111^222^333')
2) Change '^' to #13#10 (s = '111'#13#10'222'#13#10'333)
3) Call:

Code: Select all

if GetFieldLocation2(rv.RVData, field, RVData, ItemNo, 'eName5') then 
  ChangeFieldValue(RVData, s);
In this code, GetFieldLocation2 fills aOrg and X_Arrcount for 'eName5', and ChangeFieldValue uses these values to change visible text of 'eName5' field.
Thank you for your help very much!

I add the function(function GetStringListFromString(const s: String): TStringList;) and the procedure(procedure ChangeFieldValue(RVData: TCustomRVData;
const s: String);
) to my program.

then I add the RVInsertItems.pas to my project.

The "read" button's sourcecode is as below.

Code: Select all

procedure TForm1.btnReadClick(Sender: TObject);
var ItemNo: Integer;
    RVData: TCustomRVData;
    ItemNoStr :string;
    s         :string;
begin
    s:='111'+#13#10+'222'+#13#10+'333';
    if GetFieldLocation2(Srv.RichViewEdit.RVData, 'eName5', RVData, ItemNo, ItemNoStr) then
    ChangeFieldValue(RVData, s);
end;
I run my program.It's like this.
http://www.cnblogs.com/mikalshao/galler ... 95270.html
then I click the "read" button,my program is like this.
http://www.cnblogs.com/mikalshao/galler ... 95271.html

not I hope:
http://www.cnblogs.com/mikalshao/galler ... 95250.html

why?

My program Form1.create's sourcecode is as below.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var r,c: Integer;
begin
  srv.RichViewEdit.Clear;
  prInitTable01;
end;

procedure TForm1.prInitTable01;
var r,c,m,n: Integer;
begin
  m:=2;
  n:=14;
  table1 := TRVTableItemInfo.CreateEx(m,n, srv.RichViewEdit.RVData);
  for r:=0 to m-1 do
  begin
    for c:=0 to n-1 do
    table1.Cells[r,c].Clear;
  end;
  table1.BorderWidth := 0;
  table1.CellBorderWidth := 0;
  table1.CellBorderStyle := rvtbColor;
  table1.CellBorderColor := clwhite;
  table1.BorderStyle := rvtbColor;
//  table1.ClearLeft:=TRUE;

  //table0.OnCellEditing := OnCellEditing01;
  
  with table1 do begin
    Cells[0,12].AddNL('ГЕХпєЕ',0,0);

    Cells[1,0].AddNL('РХГы',0,0);
    Cells[1,2].AddNL('РФ±р',0,0);
    Cells[1,4].AddNL('ДкБд',0,0);
    Cells[1,6].AddNL('їЖ±р',0,0);
    Cells[1,8].AddNL('ІЎКТ',0,0);
    Cells[1,10].AddNL('ґІєЕ',0,0);
    Cells[1,12].AddNL('ЧЎФєєЕ',0,0);

    //----РґИлTag
    Cells[0,13].Clear;
    Cells[0,13].AddNLTag('eName1',6,0,Integer(StrNew('eName1')));

    //Cells[0,13].AddTextBlockNLA('ssss',6,0,Integer(StrNew('eName1')));
    Cells[1,1].Clear;
    Cells[1,3].Clear;
    Cells[1,5].Clear;
    Cells[1,7].Clear;
    Cells[1,9].Clear;
    Cells[1,11].Clear;
    Cells[1,13].Clear;

    Cells[1,1].AddNLTag('eName2',6,0,Integer(StrNew('eName2')));
    Cells[1,3].AddNLTag('eName3',6,0,Integer(StrNew('eName3')));
    Cells[1,5].AddNLTag('eName4',6,0,Integer(StrNew('eName4')));
    Cells[1,7].AddNLTag('eName5',6,0,Integer(StrNew('eName5')));
    Cells[1,9].AddNLTag('eName6',6,0,Integer(StrNew('eName6')));
    Cells[1,11].AddNLTag('eName7',6,0,Integer(StrNew('eName7')));
    Cells[1,13].AddNLTag('eName8',6,0,Integer(StrNew('eName8')));
  end;
  srv.RichViewEdit.InsertItem('', table1);
end;

It's only an "eName5" tags.Do I need to create serval "eName5" tags?

Please help me.

Thanks
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

Dear Sergey Tkachenko,

Thank you for your help.

I modify your function as below.

Code: Select all

    procedure ChangeFieldValue(RVData: TCustomRVData;
  const s: String);
var ParaNo, StyleNo, Tag: Integer;
    sl: TStringList;
    i, Cnt: Integer;
begin
  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.GetItemStyle(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;
    
then, I debug my program.
the read button's code is as below.

Code: Select all

  procedure TForm1.btnReadClick(Sender: TObject);
var ItemNo: Integer;
    RVData: TCustomRVData;
    ItemNoStr :string;
    s,a,b,c:string;
begin
  form1.srv.Visible:=false;
  //s:='111';
  s:='111'+#13#10+'222'+#13#10+'333';
  //s:=X_result;
  if GetFieldLocation2(Srv.RichViewEdit.RVData, 'eName15', RVData, ItemNo, ItemNoStr) then
    ChangeFieldValue(RVData, s);
  form1.srv.Visible:=true;
  form1.srv.Format;
end;
   
s:='111'; or s:='111'+#13#10+'222'+#13#10+'333';
both ok.The program can delete or insert the tags automatically.

But It's not steady.
I run my program. then click the read button.It's ok.
If I click again the read button.The error image is as below.
http://www.cnblogs.com/mikalshao/galler ... 95278.html

why?
Please help me check it.
Thanks
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

I create two new button.(button1,button2)

their sourcecode is similar to the read button.

the different is s string;

The read button's is "s:='111';"
The button1's is "s:='111'+#13#10+'222';"
The button2's is "s:='111'+#13#10+'222'+#13#10+'333';"

I run my program.
If I click the button order is read-->button1-->button2.It's ok.
But If the order is button2-->button1 or button2-->read or button1-->read ,It's error.The detail is as below.
http://www.cnblogs.com/mikalshao/galler ... 95279.html
If read-->button2 or button1-->button2.It's ok.

why?

Please help.

Thanks
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

I write off the two sourcecode as below in the read,button1,button2 button.

Code: Select all

 
form1.srv.Visible:=false;
form1.srv.Visible:=true;
then I run my program. I click the buttons from the read ,button1,button2.
At first, It's can switch successful.
But I switch serval times,the error also be found.

The error is like this.
http://www.cnblogs.com/mikalshao/galler ... 95278.html

Please help.

Thanks
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Can you create a simple compilable project (preferably not using database tables) and send it to me?
I'll try to fix it.
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

Sergey Tkachenko wrote:Can you create a simple compilable project (preferably not using database tables) and send it to me?
I'll try to fix it.
Thank you.

I have uploaded my program.The url is as below.
http://files.cnblogs.com/mikalshao/DZBL-test.rar

The main button is Save,read,button1,button2.
The Save button is similar to the procedure inserting to database .Save the eName15's data to the variable X_result.
The read button is similar to the procedure reading the data from database .Read the data from the variable X_result to the eName15 tag.

Please help.

Thanks
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

This link does not work (it requires me to log in?)
Post Reply