Storing the original index of each character in a TRichEdit....

Hi experts... I have 2 TRichEdits. The indexing and sequence of the characters within them is important to my project and therein lies my question. To illustrate, let's say I have:

abcdefghi

... as the contents of the 1st TRichEdit... the indexing of them being naturally a=1, b=2, c=3, d=4, etc. I then copy the contents of RichEdit1 to RichEdit2. Then in RichEdit2 I play around with the contents a bit and re-arrange the letters... for example maybe like this:

dagbecifh

I would still like to be able to obtain - when I examine each character individually - the origin index position that it was in before all the re-arranging was done. So while traversing the contents of RichEdit2 from left to right, I could retrieve 4 for the 1st character d, then retrieve 1 for the next character a, then retrieve 7 for the next character g, and so on.
    Is there any way, or anywhere for a TRichEdit to store such information? If there was a separate "tag" property amongst the Attributes of a RichEdit, that would be perfect for this, but it doesn't look like there is - there's just one 'tag' property for the whole RichEdit. Would anyone have any thoughts on a solution for this?

Thanks
    Shawn
shawn857Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jimyXCommented:
Hi Shawn,

Since there will be many options, the nature of your task will determine the effective solution, also to come with practical solution to conform your actual task, is there any differences from what you stated and what you actually doing? Also will there be any duplicates in RE1? If yes how to manage the duplication indexes?

i.e:
1. Is it always one char and the index will be its position?
abcdefghi
a=1, b=2, c=3...etc

2. Could it be something like this:
abcdefghi
a=100, b=24, c=3...etc.

3. Or something completely different?

If it's 1 from above, then you can use "Pos()" function as follows:
Drop three RichEdits and a button.
At the button's OnClick event:
procedure TForm1.Button1Click(Sender: TObject);
var
  ch: Char;
  i: Integer;
begin
  RichEdit1.Text:= 'abcdefghi';
  RichEdit2.Text:= 'dagbecifh';
  RichEdit3.Clear;
  for i:= 1 to length(RichEdit2.Lines.Strings[0]) do
    begin
      ch:= RichEdit2.Lines.Strings[0][i];
      RichEdit3.Lines.Add(ch+' = '+ inttostr(pos(ch, RichEdit1.Lines.Text)))
    end;
end;

Open in new window


Just for illustrating.
0
shawn857Author Commented:
Thanks Jimy... but the text in RichEdit1 could have many (or all) the same character. It could be:

aaabbbaa

...and I rearrange it to:

baaabaab

I could move the 1st 'a' in Position 1 to a new spot in Position 7. I'd like to be able to still identify that 'a' as originally coming from Position 1. You see?

Thanks!
    Shawn
0
jimyXCommented:
Apart from the index, how do you differentiate between all those a's?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

shawn857Author Commented:
Only the original index position Jimy... all those a's can be exactly the same as each other in style, color, font... same in every way.

Thanks
   Shawn
0
jimyXCommented:
Then how you can tell which "a" is this: baaabaab from the original aaabbbaa?
It could be 1, 2, 3, 7, or 8? So which is acceptable and which is not?
0
shawn857Author Commented:
You can't tell by just looking, but my hope/wish is to find a way where the original index position of that 'a' gets "carried along" with it, no matter where you put that 'a'.

Thanks
   Shawn
0
jimyXCommented:
Shawn, i must go now. I will be back after couple of hours.
Will think of a way to tackle this, as you explained.
0
shawn857Author Commented:
Thank you Jimy!
0
shawn857Author Commented:
I think I found a little trick Jimy...and it looks like it solves my problem. Ideally, I wanted something like a "tag" property in the Attibutes for each character. As an experiment, I tried storing my index values in the "Name" attribute for each character, just to see what would happen. Well, doing so causes your chosen font to be switched to the "default" font - Arial 20 size Bold. But the index value I store in "Name" gets saved properly even as I re-arrange my text around as much as I please! The only problem is that I have to use the "default" font size (Arial 20 Bold) in my TRichedit, which is no problem for me (I was already using a very large Lucida Console font size).
   So bottom line - this works for me... perfectly! It's a good little trick if you can live with the big font size - it basically gives you a free "tag" field to store a value in for each character, along with color, style, pitch, etc.

Thanks!
    Shawn
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Geert GOracle dbaCommented:
just my 2 cents ...

in html you can <span class="id1">L</span> every letter
move a letter would be like moving a <span></span> ...

don't really see a point in doing this ... but who cares anyway

html / rtf  ... same principal
0
shawn857Author Commented:
Geert - I don't really follow what your point is there....

Regards
   Shawn
0
jimyXCommented:
I see my solution was not at any help for you.
Feel free to refund your points.
0
shawn857Author Commented:
Found my own solution by fiddling with it enough...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.