Class reference?

Hello fellow programmers,

I have a custom Thread class which is used by what I call the ‘main’ class. I can’t acces the (public) properties of this main class from within the thread class:

TMain = public class
public Something
public a : TThread

TThread = public class(thread)
public method NeedsSomethingFromTMain

I’m guessing TThread needs a reference to TMain to get his own ‘parent-properties’. I suppose this is really basic stuff, but I can’t figure it out. Can you point me in the right direction?

Hello,

I'm guessing TThread needs a reference to TMain to get his own 'parent-properties'.

If I understand correctly what you are trying to achive use next tips

  1. You can add a property into TThread class that points into TMain class like that:
TThread = public class
public
  property TMainProperty: TMain;
end;
  1. Access to TMain class from TThread class is look like this:
method TThread.NeedsSomethingFromTMain;
begin
  TMainProperty.Something();
end;
  1. But before accessing to TMain class you should initialize the TMainProperty. You can do this when initializing your “a” (TThread) property, e.g.
constructor TMain;
begin
  a := new TThread();
  a.TMainProperty := self;
end;

Hope that helps.