Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 148
  • Last Modified:

Knowing on which character is klicked

Hello,

Here are some questions I can't find a solution for.

1) Is it possible to store ± 1100 characters in one string?

2) Is it possible when clicked (or doubleclicked) on a string (text.property) in an edit field, to know on which character (count?) you clicked.  By example: if the value of the text property of an editfield is 'Jenny Jones' and you clicked with your mousepointer on the letter 'o' that the result you get is 8 (8 character of the text.property).

3) If there is a solution for question 2, is it then also possible to use it in a grid.  So when you clicked that you know on which record and in that record on which field and on which (count) character in that specific field.

Al solutions welcome.

Ka1a.

PS sorry for my poor English.
0
ka1a
Asked:
ka1a
1 Solution
 
kretzschmarCommented:
1) yes
2) selstart is changed after one click->just get its value->pos := edit1.selstart+1; //selstart is zerobased
3) see 2, but not possible in all cases
0
 
geobulCommented:
Hi,

1) Yes (up to 2MB)

2)
function GetClickedCharPos1(Sender: TObject): int64;
begin
  result := 0;
  if (Sender is TEdit) then
    result := (Sender as TEdit).SelStart + 1;
end;
// or
function GetClickedCharPos2(Sender: TObject): int64;
begin
  result := 0;
  if (Sender is TWinControl) then
    result := LoWord(SendMessage((Sender as TWinControl).Handle,EM_GETSEL,0,0)) + 1;
end;

procedure TForm1.Edit1Click(Sender: TObject);
begin
  ShowMessage(IntToStr(GetClickedCharPos1(Sender)));
end;

Regards, Geo
0
 
lopemCommented:
listening
0
 
ka1aAuthor Commented:
Hi,

Thanks for the solutions.  That where the answers I was looking for.
It seems you both answered at the same time.  Is it possible for me to give you both 50 points and if yes, how do I have to do that.

Thanks.

Ka1a.
0
 
geobulCommented:
Accept kretzschmar's comment as an answer here (50 points). He was the first who answered your question.

If you wish to give additional points to me, you may ask another question titled 'points for geobul'.

Regards, Geo
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now