Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Not A Function
Sun, Apr 17 2016 4:01 PMPermanent Link

squiffy

Telemix Ltd.

Avatar

I have the below defined in a Unit :

type TModelClients = class(TObject)
  public
     property ID : Integer read ReturnID;
     ...

  protected
     function ReturnID : Integer;

...
implementation

function TModelClients.ReturnID : Integer;
begin
  Log('arrggh');
  Result:=1;
end;


I call it like this :

procedure TfrmAllocNum2.butSetMarginClick(Sender: TObject);
var
  m : TModelClients;
  i : Integer;
begin
  m:=TModelClients.Create;
  i := m.ID;
end;


But I get a window with this message in it from the i:=m.ID line

Error : m.returnid is not a function.

Can anyone save me from madness?
Sun, Apr 17 2016 4:31 PMPermanent Link

squiffy

Telemix Ltd.

Avatar

Ok, I know why this is - Sender is a TDataset and not my class. Obvious really, but wood/trees/etc.

This morphs my question into - is there any way I can reference the class instance I created in the AfterLoad event for a TDataSet contained within that class? I want to be able to call a class function for the instance AFTER the AfterLoad event has fired. I know I could create a global variable, but that's clunky especially if I want to create many of these on a single form all possibly "live" at the same time.

I am declaring the class in a button click, but the AfterLoad event just has Sender passed. I seem unable to access the Parent which I assume would be the class instance.

I'm getting myself a little confused, I think...
Sun, Apr 17 2016 7:43 PMPermanent Link

Raul

Globestar Systems

Team Elevate Team Elevate

On 4/17/2016 4:31 PM, squiffy wrote:
> Ok, I know why this is - Sender is a TDataset and not my class. Obvious really, but wood/trees/etc.
> This morphs my question into - is there any way I can reference the class instance I created in the AfterLoad event for a TDataSet contained within that class? I want to be able to call a class function for the instance AFTER the AfterLoad event has fired. I know I could create a global variable, but that's clunky especially if I want to create many of these on a single form all possibly "live" at the same time.

TDataset is based on TComponent that has a generic data property
(http://www.elevatesoft.com/manual?action=viewprop&id=ewb2&comp=TComponent&prop=Data)


Would that work for you ? (i.e create an instance of your class and
assign to TDataSet.Data)

Raul
Mon, Apr 18 2016 3:37 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

Raul - works perfectly, thanks!

I think I may need to rethink how I'm doing what I'm doing, but this can sit in until I do.
Mon, Apr 18 2016 5:51 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

,,,and extra well done for getting a meaningful answer from that dogs dinner of a question. I just re-read it, and it doesn't make a lot of sense (I've missed out a major portion of how it works).

I shouldn't ask questions when I'm confused, and therein lies the problem Smile
Image