Re: [DUG] Dumb Friday Question

2007-05-06 Thread Alister Christie
I'd tend to agree factory methods can be very helpful in simplifying code. Alister Christie Computers for People Ph: 04 471 1849 Fax: 04 471 1266 http://www.salespartner.co.nz PO Box 13085 Johnsonville Wellington Neven MacEwan wrote: You guys don't consider a constructor a function then?

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Judd, Struan \(eCargo\)
Jeremy Coulter wrote: Hi All. This is a question that might be infulenced by some serious lack of sleep :-) I have a funtion. Its return result is a TStringlist. In my code I create a TStringlist then add my values to it, then pass this to the RESULT varaible for the function. Now,

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Leigh Wanstead
Hi Jeremy, I think you need this one http://v.mahon.free.fr/pro/freeware/memcheck ;-) Regards Leigh www.smootharm.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Jeremy Coulter Sent: Friday, 4 May 2007 1:28 p.m. To: delphi@delphi.org.nz

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Myles Penlington
Group - Delphi List Subject: RE: [DUG] Dumb Friday Question Hi Jeremy, I think you need this one http://v.mahon.free.fr/pro/freeware/memcheck ;-) Regards Leigh www.smootharm.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf

RE: [DUG] Dumb Friday Question

2007-05-03 Thread David Brennan
of the above issue. Myles. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Judd, Struan (eCargo) Sent: Friday, 4 May 2007 01:46 To: [EMAIL PROTECTED]; NZ Borland Developers Group - Delphi List Subject: RE: [DUG] Dumb Friday Question Jeremy Coulter wrote: Hi All

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Xander \(GMail\)
] On Behalf Of Leigh Wanstead Sent: Friday, May 04, 2007 1:55 PM To: [EMAIL PROTECTED]; NZ Borland Developers Group - Delphi List Subject: RE: [DUG] Dumb Friday Question Hi Jeremy, I think you need this one http://v.mahon.free.fr/pro/freeware/memcheck ;-) Regards Leigh

Re: [DUG] Dumb Friday Question

2007-05-03 Thread Robert martin
Hi Your code would leak. You are creating an object and not freeing it. The calling function that retrieves the result must handle the freeing of the object. It might be clearer if you just change the function to a procedure that takes a TStringList as a parameter. i.e //Replacement

Re: [DUG] Dumb Friday Question

2007-05-03 Thread Rohit Gupta
I would go along with Robert, you should not return complex types from functions that create them, It makes the code messy, you create it in one place and free it in another. Any sort of code analyser would also complain about this. You could return a string = stringlist.text and assign it

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Conor Boyd
I would endorse Rob's answer here. I don't consider it just a question of potential leaks, it's about making the intentions of your code clear. The intention of who has the responsibility for object lifetime is much, much clearer in Delphi if your caller creates the Stringlist that it wants

Re: [DUG] Dumb Friday Question

2007-05-03 Thread Neven MacEwan
You guys don't consider a constructor a function then? I think its totally stylistic, if you want to have functions returning objects fine, just make it plain that they do, IMHO Neven I would endorse Rob's answer here. I don't consider it just a question of potential leaks, it's about

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Paul Heinz
David asked: Surely you are joking? Is that right? Delphi.NET doesn't have garbage collection? Yes, it does. I'm guessing they're referring to the IDispose interface and pattern which Delphi.NET automagically maps calls to Free onto so that resources _other_ then memory get released early.

RE: [DUG] Dumb Friday Question

2007-05-03 Thread John Bird
PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Xander (GMail) Sent: Friday, 4 May 2007 2:02 p.m. To: 'NZ Borland Developers Group - Delphi List' Subject: RE: [DUG] Dumb Friday Question Jeremy, If the function returns a TStringList then it should be the responsibility of the caller

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Sean Cross
-Original Message- From: [EMAIL PROTECTED] [mailto:delphi- [EMAIL PROTECTED] On Behalf Of Neven MacEwan Sent: Friday, 4 May 2007 2:45 p.m. To: NZ Borland Developers Group - Delphi List Subject: Re: [DUG] Dumb Friday Question You guys don't consider a constructor a function

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Conor Boyd
I do consider a constructor a function to some extent, but it's a function which has compiler support. I.e. the compiler guarantees to tidy up a partially constructed result object if an exception gets raised in the constructor. Also, everybody knows that a constructor returns a complex object;

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Conor Boyd
Note for clarity, although I think we all understand this anyway. What we're talking about here is a function returning _and handing off_ an object. This is different to exposing an object (e.g. a StringList) as a property of a class, e.g. the Items property of a combobox or similar. In that

Re: [DUG] Dumb Friday Question

2007-05-03 Thread Robert martin
Warm fuzzy feelings :) Rob Martin Software Engineer phone +64 03 377 0495 fax +64 03 377 0496 web www.chreos.com Wild Software Ltd Rohit Gupta wrote: I would go along with Robert, you should not return complex types from functions that create them, It makes the code messy, you create

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Conor Boyd
That code's safe from a memory POV, but I wouldn't have coded it like that personally, because to me, the intentions aren't clear. I believe that the fact that you had to go and look at the implementation supports my suggestion of trying to clarify intentions. I haven't used TFindFile (so

RE: [DUG] Dumb Friday Question

2007-05-03 Thread karlreynolds
You guys don't consider a constructor a function then? I think its totally stylistic, if you want to have functions returning objects fine, just make it plain that they do, IMHO Neven The downside to having creator functions returning objects is that you have to duplicate the code in

RE: [DUG] Dumb Friday Question

2007-05-03 Thread karlreynolds
you have to duplicate the code in TObject.Create to ensure safety What I meant was the ClassHandleException code which runs when an exception occurs during a constructor. Cheers, Carl ___ NZ Borland Developers Group - Delphi mailing list Post:

Re: [DUG] Dumb Friday Question

2007-05-03 Thread Neven MacEwan
Hi The solution is to use interfaces, but if you don't it would be difficult to implement a factory pattern There is this thing in OO language users which seems to be the muddy area between scalars and objects, ie is a TStringList a simple object or a complex scalar, of course it doesn't help

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Tim Jarvis
: Friday, 4 May 2007 12:22 PM To: [EMAIL PROTECTED]; NZ Borland Developers Group - Delphi List Subject: Re: [DUG] Dumb Friday Question I would go along with Robert, you should not return complex types from functions that create them, It makes the code messy, you create it in one place and free

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Leigh Wanstead
- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Tim Jarvis Sent: Friday, 4 May 2007 4:30 p.m. To: NZ Borland Developers Group - Delphi List; [EMAIL PROTECTED] Subject: RE: [DUG] Dumb Friday Question Hi Guys, Hope you don't mind me sticking my nose in here. Firstly I agree

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Conor Boyd
] On Behalf Of Rohit Gupta Sent: Friday, 4 May 2007 12:22 PM To: [EMAIL PROTECTED]; NZ Borland Developers Group - Delphi List Subject: Re: [DUG] Dumb Friday Question I would go along with Robert, you should not return complex types from functions that create them, It makes the code messy, you

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Karl Reynolds
, Carl _ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tim Jarvis Sent: Friday, May 04, 2007 4:30 PM To: NZ Borland Developers Group - Delphi List; [EMAIL PROTECTED] Subject: RE: [DUG] Dumb Friday Question Hi Guys, Hope you don't mind me sticking my nose in here

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Moretti, Giovanni
Tim Jarvis [EMAIL PROTECTED] wrote: Firstly I agree with the sentiment that you should try and avoid creating objects in one place and freeing in another ... This whole discussion is close to my heart. I've got a similar horrible situation where I've got a factory that produce objects

Re: [DUG] Dumb Friday Question

2007-05-03 Thread Neven MacEwan
Giovanni If the sun is shining in palmy its probably 4 below 0 You should definatetly be using intefaces not pointer for this this way you can do reference counting Neven Tim Jarvis [EMAIL PROTECTED] wrote: Firstly I agree with the sentiment that you should try and avoid creating

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Myles Penlington
PROTECTED] On Behalf Of Neven MacEwan Sent: Friday, 4 May 2007 05:13 To: NZ Borland Developers Group - Delphi List Subject: Re: [DUG] Dumb Friday Question Giovanni If the sun is shining in palmy its probably 4 below 0 You should definatetly be using intefaces not pointer for this this way you can do

Re: [DUG] Dumb Friday Question

2007-05-03 Thread Neven MacEwan
- I was there for a few years (a long time ago). Myles. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Neven MacEwan Sent: Friday, 4 May 2007 05:13 To: NZ Borland Developers Group - Delphi List Subject: Re: [DUG] Dumb Friday Question Giovanni

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Myles Penlington
. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Neven MacEwan Sent: Friday, 4 May 2007 05:49 To: NZ Borland Developers Group - Delphi List Subject: Re: [DUG] Dumb Friday Question Myles As you said its better than nothing but if you really want to do some

RE: [DUG] Dumb Friday Question

2007-05-03 Thread Tim Jarvis
May 2007 3:00 PM To: 'NZ Borland Developers Group - Delphi List'; [EMAIL PROTECTED] Subject: RE: [DUG] Dumb Friday Question It isn't different, but that's because: List := TStringList.Create; PopulateList(List); try if List.Count 0 then begin ...do lots of stuff