Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

StringList Objects

Posted on 1998-10-16
4
Medium Priority
?
735 Views
Last Modified: 2013-11-23
I am interested in using the Objects property of a StringList to associate objects with certain Lines of a RichEdit. However, Delphi's help says that certain StringList objects ignore the Object property because "they don't make sense, like Lines in a Memo". I'm not sure exactly what that means but is there a way to associate Objects with Lines in a memo (or richedit) object?
0
Comment
Question by:jcglen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:jcglen
ID: 1343156
Edited text of question
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 100 total points
ID: 1343157
What the help is saying is that the designers of the TMemo (and probably TRichEdit) objects couldn't think of a reason to do it and so didn't.

The easiest way is to have a TList that stores the objects. You could match the index of a line of text in the lines property to the index of an object in the TList object.

You will need to manage what happens when the user deletes/adds lines etc whch may be a little awkward, but if it is to be read-only this should be fine...

Cheers,

Raymond.
 
0
 
LVL 1

Expert Comment

by:Edo082297
ID: 1343158
Hello jcglen
   Associating line indexes with TList pointers is not a good idea in my opinion. I use the Objects member (or related Data member in TListItems) a lot because they are very useful. There are two ways to do what you are trying to do. First of all, since the Lines property of a TRichEdit is itself of type TStrings, you could associate your object with Lines.Objects. The second more complicated thing keeps your objects associated with your string list (which is what you want to do, right?).

First, declare a small class, called TLine:

  TLine = class
  private
    FLine : String;
  end;

Now, to associate a given line with your object, create an object of type TLine and associate it with your string list member.

  MyLine := TLine.Create;
  MyLine.FLine := RichEdit1.Lines[y];
  MyStringList.Objects[x] := MyLine;

Now you have kept the text in your string list and have an associated object. You can dereference the string like this:
 
  TLine(MyStringList.Objects[AnIndex]).FLine;

You can also search your stringlist using IndexOf, IndexOfObject, and so on (just like you can with Lines). The Objects and Data members of various classes in Delphi are very powerful in this regard.

Finally, in your destructor, you have to free the memory you have allocated for each of these objects. Do the following:

  for i := 0 to Pred(MyStringList.Count) do
    TLine(MyStringList.Objects[x]).Free;

Regards,
Edo

0
 
LVL 1

Expert Comment

by:Edo082297
ID: 1343159
I am tired, there is a mistake in the destructor, [x] should read [i].

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question