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

x
?
Solved

Create type with index....

Posted on 1999-07-01
8
Medium Priority
?
135 Views
Last Modified: 2010-04-06
I would like to create a type with one TList, and one TStringlist that can be accessed with an index. To illustrate what I mean, I can show what I want to do. Code as follows:

MyType[i].List := Object (TObject)
MyType[i].Name := Name (string)

How do I accomplish this?

0
Comment
Question by:volavy
[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
  • 5
  • 3
8 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1385705
hi volavy

why not use a TStringlist?
you can add a string, and to each string a list of objects
(in your case only one per string)

meikl


0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1385706
oops, sorry,
only one object per string, not a list of objects,
but this matches also what you want.

meikl
0
 

Author Comment

by:volavy
ID: 1385707
How exactly do you mean? Can I have an object in my stringlist?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 1385708
hi volavy,

that mean i

var sl : TStringList;
begin
  sl := TStringList.Create;
  sl.AddObject(Button1.ClassName,Button1);  //add a string and a object
. . .

  s := sl[i]; //get the string
  MyObj :=  sl.Objects[i]; //get the Object

meikl

0
 

Author Comment

by:volavy
ID: 1385709
Thank you, I didn't know it could be done this way.

The problem is, I need two different strings that can be associated with the object (didn’t mention it before). I don't think it can be solved this way, or can it ?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1385710
hmm, ok,

a simple solution could be to define a record

type
  PMySpecialRec = ^TMySpecialRec;
  TMySpecialRec = record
                               s1 : String[100];
                               s2 : String[100];
                               O : TObject;
                             end;

var
  PSRec : PMySpecialRec;
  List : TList;
...
  List := TList.Create;
...
now you can do

Store

  New(PSRec);
  PSRec^.S1 := 'MyFirstString';
  PSRec^.S2 := 'MyFirstString';
  PSRec^.O := MyObj;
  List.add(PSRec);

Get
 
  SVar1 := PMySpecialRec(List[i])^.S1;
  SVar2 := PMySpecialRec(List[i])^.S2;
  ObjectVar := PMySpecialRec(List[i])^.O;

by this don't forget to dispose the stored pointer before you free the tlist

meikl


0
 

Author Comment

by:volavy
ID: 1385711
Ok, thanks. It works perfectly...


Please purpose an answer.


Best regards
/Peter
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
ID: 1385712
hi peter,
glad that i helped you,
good luck again
meikl ;-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

715 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