Recent

Author Topic: Objects and ObjectList design question  (Read 1596 times)

jbmckim

  • Full Member
  • ***
  • Posts: 144
Objects and ObjectList design question
« on: February 21, 2018, 08:26:25 pm »
I've read some of the forum posts on this but I have an implementation issue that is escaping me.

I have a class that will have n instantiations  based on a number of instruments that are connected. I want to create a list of the created objects and subsequently assign, reference and execute code in them. 

In .Net, there's a very useful pattern for this in which a local copy of the class is created, the object is copied to the local version and the work is executed in the local version. 

Here's VB.Net example illustrating (hopefully) what I'm talking about:

Code: Pascal  [Select][+][-]
  1. Dim MyLocalOject As MyClass
  2.  
  3. For Each MyLocalObject in MyGlobalListOfObjects Do
  4.    'work on individual element done here'
  5.    MyLocalObject.RecordNumber = 1
  6.    ...
  7.    ...
  8. Next MyLocalObject 'get the next object in the list'
  9.  

Ideally, I'd like to mimic this pattern as closely as possible.  If that's a problem, what would be an efficient LP equivalent?

I've experimented with a couple different approaches but have hit errors on each.  This may be just a matter of correcting those errors but I'd be interested if there's a "usual" LP pattern for this implementation.

Thanks.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: Objects and ObjectList design question
« Reply #2 on: February 21, 2018, 10:31:01 pm »
You need generic container/list types though, otherwise you need an extra typecast.

Code: Pascal  [Select][+][-]
  1. var p : pointer;
  2.  
  3.  for p in someTObjectList do
  4.    tsomeobject(p).RecordNumber:=1;
  5.  

 

TinyPortal © 2005-2018