BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Design question (global variable)

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
Joe Otten
Guest





PostPosted: Mon Jul 21, 2003 11:28 am    Post subject: Design question (global variable) Reply with quote




OK, we have 3 packages:

Package A is mine
Package B is third party or Borland or something - can't touch
Package C is mine.

A requires B. C requires A and B.

Currently I have a method in A which calls a method in B, which calls in
turn a method in C of a class that C has registered with B, which is a
subclass of a class that B knows about.

Problem: I want to pass an additional item of information from the class in
A to the class in C (a reference to itself would do).

Of course I could use a global variable (I didn't say it *just* to get your
attention), so in A

Assert(MyGlobal = nil);
MyGlobal := Self;
try
classinB.DoStuff;
finally
MyGlobal := nil;
end;

And I could protect it against threading problems if that was important.

But is there a good way to do it?

Joe



Back to top
Joe Otten
Guest





PostPosted: Mon Jul 21, 2003 2:41 pm    Post subject: Re: Design question (global variable) Reply with quote





Quote:
You can solve this by adding a property to TClassC which could be set from
within TClassA.DoSomething:

That would work, except that ClassA never gets a reference to the instance
of ClassC that is doing the work.

Joe



Back to top
John Elrick
Guest





PostPosted: Mon Jul 21, 2003 3:32 pm    Post subject: Re: Design question (global variable) Reply with quote




"Joe Otten" <joe (AT) datator (DOT) co.uk> wrote

Quote:

OK, we have 3 packages:

Package A is mine
Package B is third party or Borland or something - can't touch
Package C is mine.

Don't call B directly...

Package MyClient is mine
Package ThirdParty is third party or Borland or something - can't touch
Package MyServer is mine.


ThirdParty.Method;

constructor TMyServer.Create(const aThirdParty: TThirdParty);
begin
FThirdParty := aThirdParty;
FThirdParty.RegisterMethod(CallbackMethod);
end;

procedure TMyServer.Method(const aClient: TMyClient);
begin
FThirdParty.Method;
...do something with client



So:

localServer := TMyServer.Create(aThirdParty);
or
localServer := TMyServer.Create(TThirdParty.Create);

localServer.Method(Self);



John



Back to top
Bryan Crotaz
Guest





PostPosted: Wed Jul 23, 2003 12:32 pm    Post subject: Re: Design question (global variable) Reply with quote

Declare an interface on classC, and query objectInB for it. If you find it,
it must be one of yours and you can use the interface to pass data to it.

Bryan


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.