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

How the Cursor move in the Tags of TSrichViewEdit ?

Post by srvsxf »

First,thank your help me!

Now,I find a problem.I want to use the Tags in the TSrichViewEdit .
The user want to used the "Enter" key to move the Cursor.
How I do?


Thank you for your help! I'm very impatient.

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

Post by Sergey Tkachenko »

1) How do you want to use tags?
2) Where do you want to move the caret when the user pressed Enter?
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Cusor Move

Post by srvsxf »

Sergey Tkachenko wrote:1) How do you want to use tags?
2) Where do you want to move the caret when the user pressed Enter?
Sorry! I don't describe it carefully.
My sourcecode is as below.
//-------((
procedure TForm1.FormCreate(Sender: TObject);
var r,c: Integer;
begin
table1 := TRVTableItemInfo.CreateEx(2,14, srv.RichViewEdit.RVData);
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].AddNLTag('xxxx',6,0,Integer(StrNew('eName1')));
Cells[1,1].AddNLTag('xxx',6,0,Integer(StrNew('eName2')));
Cells[1,3].AddNLTag('x',6,0,Integer(StrNew('eName3')));
Cells[1,5].AddNLTag('xx',6,0,Integer(StrNew('eName4')));
Cells[1,7].AddNLTag('xxxx'+#13+'oooooopo',6,0,Integer(StrNew('eName5')));
Cells[1,9].AddNLTag('xx',6,0,Integer(StrNew('eName6')));
Cells[1,11].AddNLTag('xx',6,0,Integer(StrNew('eName7')));
Cells[1,13].AddNLTag('xxx',6,0,Integer(StrNew('eName8')));
end;
srv.RichViewEdit.InsertItem('', table1);
end;
///------))

run the program ,it's as below.
http://www.cnblogs.com/mikalshao/galler ... 94404.html
I hope when the user press "enter" key,the cursor move in the place with gray backgrand.

Please help me !

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

Post by Sergey Tkachenko »

Do you want it to move to the NEXT text with gray background?
Like MS Excel moves to the next cell when user presses Enter?
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Cursor Move

Post by srvsxf »

Sergey Tkachenko wrote:Do you want it to move to the NEXT text with gray background?
Like MS Excel moves to the next cell when user presses Enter?
OK! Just it I want.
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

I want to move the Cursor in the gray background.
The best,the user use "->" not use "enter" key.because "Enter" key use to newline.

But I find an other problem.If I don't press "enter" key,I input the word "111" in the tag,I can get the word "111".If I input the word "111" ,then press "enter" key,the gray background have a new line ,I add "222" on the end of "111".I get the tag value again.It also "111".
But it's not I want.I want get the whole string "111222".How I do?

Please help me!Thanks a lot.
so I have two problem.The detail is as below.
1) use direction key move the cursor
2) press "Enter" key ,I also get the whole value "111222"

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

Post by Sergey Tkachenko »

TSRichViewEdit has the method NextCurItem allowing to select the next item having one of the specified StyleNo. In your case, StyleNo=6.
Enter is processed in OnKeyDown event. Unfortunately, it is forbidden to move from cell to cell in OnKeyDown, so we need using PostMessage to call NextCurItem.

1) Define the constant

Code: Select all

const
  WM_GOTONEXTTEXT = WM_APP+100;
2) Add in the interface part of the form:

Code: Select all

    procedure WMGoToNextText(var Msg: TMessage); message WM_GOTONEXTTEXT;
3) Add in the implementation:

Code: Select all

procedure TForm1.WMGoToNextText(var Msg: TMessage);
begin
  srv.NextCurItem([6]);
end;
4) Add in srv.OnKeyDown:

Code: Select all

  if (Key = VK_RETURN) then begin
    PostMessage(Handle, WM_GOTONEXTTEXT, 0, 0);
    Key := 0;
  end;
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Now, about line breaks in fields.
One item cannot contain a line break inside. Because of this, your line

Code: Select all

Cells[1,7].AddNLTag('xxxx'+#13+'oooooopo',6,0,Integer(StrNew('eName5')));
is incorrect, you need using 2 calls of AddNLTag to add 2 lines.
And when you get values, you can enumerate all items having the same tag, something like this:

Code: Select all

FieldValue := '';
for i := 0 to RVData.ItemCount-1 do
  if StrComp(PChar(RVData.GetItemTag(i), 'eName5') then
    FieldValue := FieldValue+RVData.GetItemText(i);
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

Sergey Tkachenko wrote:Now, about line breaks in fields.
One item cannot contain a line break inside. Because of this, your line

Code: Select all

Cells[1,7].AddNLTag('xxxx'+#13+'oooooopo',6,0,Integer(StrNew('eName5')));
is incorrect, you need using 2 calls of AddNLTag to add 2 lines.
And when you get values, you can enumerate all items having the same tag, something like this:

Code: Select all

FieldValue := '';
for i := 0 to RVData.ItemCount-1 do
  if StrComp(PChar(RVData.GetItemTag(i), 'eName5') then
    FieldValue := FieldValue+RVData.GetItemText(i);
Thank you for your help.

I test my program with your method.

My sourcode is as below.
//--------
procedure TForm1.Button1Click(Sender: TObject);
var
FieldValue :string;
i :integer;
begin
FieldValue := '';

for i := 0 to srv.RichViewEdit.RVData.ItemCount-1 do
if Pchar(srv.RichViewEdit.RVData.GetItemTag(i))='eName5' then
FieldValue :=FieldValue+ FieldValue+srv.RichViewEdit.RVData.GetItemText(i);

showmessage(inttostr(i)+'-'+FieldValue);
end;
//--------

I copy your code test directly.
Have two problem.
1) Undeclared identifier:"RVDate"
2)The cursor stop the end of "StrComp(PChar(RVData.GetItemTag(i),".
Debug Message:')' expected but ',' found

so I modify your code as above .

I test the program. I click the button1. The message is "1-".

Please help me!

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

Post by srvsxf »

Sergey Tkachenko wrote:TSRichViewEdit has the method NextCurItem allowing to select the next item having one of the specified StyleNo. In your case, StyleNo=6.
Enter is processed in OnKeyDown event. Unfortunately, it is forbidden to move from cell to cell in OnKeyDown, so we need using PostMessage to call NextCurItem.

1) Define the constant

Code: Select all

const
  WM_GOTONEXTTEXT = WM_APP+100;
2) Add in the interface part of the form:

Code: Select all

    procedure WMGoToNextText(var Msg: TMessage); message WM_GOTONEXTTEXT;
3) Add in the implementation:

Code: Select all

procedure TForm1.WMGoToNextText(var Msg: TMessage);
begin
  srv.NextCurItem([6]);
end;
4) Add in srv.OnKeyDown:

Code: Select all

  if (Key = VK_RETURN) then begin
    PostMessage(Handle, WM_GOTONEXTTEXT, 0, 0);
    Key := 0;
  end;
Thank you for your help very much!

I think that user need used "Enter" key to new line sometime.
so,I want to use "right" key move the cursor to next tag,use "left" key move the cursor to previous tag.

how I do?

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

Post by Sergey Tkachenko »

You can change VK_RETURN to VK_RIGHT.
You can implement similar code with VK_LEFT and PriorCurItem instead of NextCurItem.
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

Sergey Tkachenko wrote:You can change VK_RETURN to VK_RIGHT.
You can implement similar code with VK_LEFT and PriorCurItem instead of NextCurItem.
Thank you for your help!

I test my program as your said yesterday. But It can't success because of some my mistake.

Today,I test again. It's ok!
Thanks.
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

srvsxf wrote:
Sergey Tkachenko wrote:Now, about line breaks in fields.
One item cannot contain a line break inside. Because of this, your line

Code: Select all

Cells[1,7].AddNLTag('xxxx'+#13+'oooooopo',6,0,Integer(StrNew('eName5')));
is incorrect, you need using 2 calls of AddNLTag to add 2 lines.
And when you get values, you can enumerate all items having the same tag, something like this:

Code: Select all

FieldValue := '';
for i := 0 to RVData.ItemCount-1 do
  if StrComp(PChar(RVData.GetItemTag(i), 'eName5') then
    FieldValue := FieldValue+RVData.GetItemText(i);
Thank you for your help.

I test my program with your method.

My sourcode is as below.
//--------
procedure TForm1.Button1Click(Sender: TObject);
var
FieldValue :string;
i :integer;
begin
FieldValue := '';

for i := 0 to srv.RichViewEdit.RVData.ItemCount-1 do
if Pchar(srv.RichViewEdit.RVData.GetItemTag(i))='eName5' then
FieldValue :=FieldValue+ FieldValue+srv.RichViewEdit.RVData.GetItemText(i);

showmessage(inttostr(i)+'-'+FieldValue);
end;
//--------

I copy your code test directly.
Have two problem.
1) Undeclared identifier:"RVDate"
2)The cursor stop the end of "StrComp(PChar(RVData.GetItemTag(i),".
Debug Message:')' expected but ',' found

so I modify your code as above .

I test the program. I click the button1. The message is "1-".

Please help me!

Thanks
Do you look this problem?

I can't also get the value .

Please help me!

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

Post by Sergey Tkachenko »

Use this function:

Code: Select all

function GetFieldValueFromRVData(RVData: TCustomRVData; const FieldName: String): String;
var i,r,c: Integer;
    table: TRVTableItemInfo;
begin
  Result := '';
  for i := 0 to RVData.ItemCount-1 do
    if (RVData.GetItemStyle(i)>=0) and
      (StrComp(PChar(RVData.GetItemTag(i)), PChar(FieldName))=0) then
      Result := Result + RVData.GetItemText(i)
    else if (RVData.GetItemStyle(i)=rvsTable) then begin
      Table := TRVTableItemInfo(RVData.GetItem(i));
      for r := 0 to table.RowCount-1 do
        for c := 0 to table.ColCount-1 do
          if Table.Cells[r,c]<>nil then
           Result := Result+GetFieldValueFromRVData(table.Cells[r,c].GetRVData, FieldName);
    end;
end;
How to use:

Code: Select all

FieldValue := GetFieldValueFromRVData(srv.RichViewEdit.RVData, 'eName5');
srvsxf
Posts: 27
Joined: Tue Sep 21, 2010 1:19 am

Post by srvsxf »

Sergey Tkachenko wrote:Use this function:

Code: Select all

function GetFieldValueFromRVData(RVData: TCustomRVData; const FieldName: String): String;
var i,r,c: Integer;
    table: TRVTableItemInfo;
begin
  Result := '';
  for i := 0 to RVData.ItemCount-1 do
    if (RVData.GetItemStyle(i)>=0) and
      (StrComp(PChar(RVData.GetItemTag(i)), PChar(FieldName))=0) then
      Result := Result + RVData.GetItemText(i)
    else if (RVData.GetItemStyle(i)=rvsTable) then begin
      Table := TRVTableItemInfo(RVData.GetItem(i));
      for r := 0 to table.RowCount-1 do
        for c := 0 to table.ColCount-1 do
          if Table.Cells[r,c]<>nil then
           Result := Result+GetFieldValueFromRVData(table.Cells[r,c].GetRVData, FieldName);
    end;
end;
How to use:

Code: Select all

FieldValue := GetFieldValueFromRVData(srv.RichViewEdit.RVData, 'eName5');
Thank you for your help!

But I 'm sorry that I can't test it successful.

I copy your function to my program.
create a button to show the value of the tag "eName5".
But found the error .

The first image is as below.
http://www.cnblogs.com/mikalshao/galler ... 94695.html
The second is
http://www.cnblogs.com/mikalshao/galler ... 94696.html
The third is
http://www.cnblogs.com/mikalshao/galler ... 94697.html

why?

Please help me.

Thanks
[/img]
Post Reply