Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calling methods within a TList

Posted on 2000-03-29
3
Medium Priority
?
212 Views
Last Modified: 2010-04-04
My TList contains a list of TTimeRecord objects, the TTimeRecord objects contain sevgeral properties and methods (Read and write). What I want to be able to do is call the methods and access the properties of a particular item in the TList by calling the TList such as:

TList.Items[3].read;

I know I can create an instance of the TTime Record and point this to the item in the TList and call it that way but this seems messy and I'm sure you should be able to do it directly in the same way as you would call an array.

Of course the TList doesn't know it's a list of TTimeRecord so this me be the problem.

Any ideas how to do this?
0
Comment
Question by:mike_tipping
[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
3 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 300 total points
ID: 2666408
Try this:

type
  TMyRecord = record
                f: function: Integer;
                .....
              end;

function f1: Integer;
begin
  Result := 24;
end;

procedure TForm1.Button1Click(Sender: TObject);
var r: TMyRecord;
    l: TList;
begin
  r.f := f1;
  l := TList.Create;
  l.Add(@r);
  ShowMessage(IntToStr(TMyRecord(l.Items[0]^).f));
  l.Free;
end;
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2667541
I think he means this: (Borrowing Epsylons code...)

type
  TMyRecord = class(TObject)
                f: function: Integer;
                .....
              end;

procedure TForm1.Button1Click(Sender: TObject);
var r: TMyRecord;
    l: TList;
begin
  l := TList.Create;
  l.Add(TMyRecord.Create);
  ShowMessage(IntToStr(TMyRecord(l[0]).f));
  l.Free;
end;

You can make this slicker again by creating your own list desencdent like this:

  TMyList = class(TObjectList)
    protected
      Function Get(Index : Integer) : TMyRecord;
      procedure Put(Index: Integer; const Value: TMyRecord);

    public
      property Items[Index : Integer] : TMyRecord read Get write Put;
  end;


function TMyList.Get(Index: Integer): TMyRecord;
begin
  Result := Inherited Get(Index);
end;


procedure TMyList.Put(Index: Integer;
                                       const Value: TMyRecord);
begin
  Inherited Put(Index, Value);
end;


Then Button1Click looks like this:

procedure TForm1.Button1Click(Sender: TObject);
var r: TMyRecord;
    l: TMyList;
begin
  l := TMyList.Create;
  l.Add(TMyRecord.Create);
  ShowMessage(IntToStr(l[0].f));
  l.Free;
end;

Cheers,

Raymond.

0
 

Author Comment

by:mike_tipping
ID: 2707311
Sorry, but I think Epsylon gave me the answer I wanted first
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 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