Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread spir
On Mon, 5 Jul 2010 16:51:54 -0300 Marcos Douglas wrote: > >> Why I ask this: > >> If not exists the variable obj2 in call obj1.createObj will happen a > >> memory leak, right? Because there is not variable to release. > > > > Do you mean using a function as a statement? (for its so-called "side

Re: [fpc-pascal] question about changing default ASCII table in thefpc 2.2.0 IDE

2010-07-05 Thread Noel and Marie
Thank you Tomas for tracking down the bug and filing the bug report. It was much appreciated. Cheers, Noel - Original Message - From: "Tomas Hajny" To: "FPC-Pascal users discussions" Cc: ; "Noel and Marie" Sent: Tuesday, July 06, 2010 5:32 AM Subject: Re: [fpc-pascal] question abou

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Reimar Grabowski
On Mon, 5 Jul 2010 16:51:54 -0300 Marcos Douglas wrote: > What do you mean "a function has effects is already bad"? > A function/procedure always has effects, don't? IMHO he means that a function should only return a value and not change the state of an object, a variable or any other program s

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Andrew Brunner
If Memory allocation is the point of discussion and you need to create objects ... You should nest the creations in order of usage. In your declarations you needed bot Object1 and Object2 as TMyObject; That said the proper usage would be: obj1:=TMyObject.Create; Try obj2:=TMyObject.Create; T

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Michael Van Canneyt
On Mon, 5 Jul 2010, Graeme Geldenhuys wrote: On 5 July 2010 22:03, Marcos Douglas wrote: The ask is: If a function creates, inside, a object and there is no variable to receive this pointer, will happen a memory leak? Yes you will have a memory leak. Easy way to test is to enable the heaptr

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Graeme Geldenhuys
On 5 July 2010 22:03, Marcos Douglas wrote: > The ask is: > If a function creates, inside, a object and there is no variable to > receive this pointer, will happen a memory leak? Yes you will have a memory leak. Easy way to test is to enable the heaptrc unit (compiler option -gh). On terminating t

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Mattias Gaertner
On Mon, 5 Jul 2010 17:46:39 -0300 Marcos Douglas wrote: > On Mon, Jul 5, 2010 at 5:30 PM, Mattias Gaertner > wrote: > > > > No. This will create a mem leak. > > Thanks Mattias, I expect that... > > > On Mon, Jul 5, 2010 at 5:39 PM, Martin wrote: > > > > that is the same as if you wrote > > >

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Marcos Douglas
On Mon, Jul 5, 2010 at 5:30 PM, Mattias Gaertner wrote: > > No. This will create a mem leak. Thanks Mattias, I expect that... On Mon, Jul 5, 2010 at 5:39 PM, Martin wrote: > > that is the same as if you wrote > >  TsomeObject.create; > > without assigning the created object to a variable. Both

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Martin
On 05/07/2010 21:26, Marcos Douglas wrote: If I have a variable myObj, I can do this: someObj := myObj.createObj; This is the same: someObj := TsomeObject.create; Rigth? But if a remove the variable *someObj* and call like this: myObj.createObj; // I _removed_ the *someObj* here!!! What will

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Mattias Gaertner
On Mon, 5 Jul 2010 17:26:52 -0300 Marcos Douglas wrote: >[...] > But if a remove the variable *someObj* and call like this: > myObj.createObj; // I _removed_ the *someObj* here!!! > > What will happen with the "result" variable? Is it released by the compiler? No. This will create a mem leak.

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Marcos Douglas
On Mon, Jul 5, 2010 at 5:14 PM, Martin wrote: > > That would be, if a crash happens inside obj1.createObj? Because otherwise > the obj is stored in obj2. > > If it happens in there, then handle it in there => there is result as > variable. > > function TMyObject.creatObj : TSomeObj; > begin >  res

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Martin
On 05/07/2010 21:03, Marcos Douglas wrote: I use this technique a lot, but thanks :) Unfortunately, this is not the *problem*. The ask is: If a function creates, inside, a object and there is no variable to receive this pointer, will happen a memory leak? In my eg before, this is Okay: obj2 :=

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Marcos Douglas
Hi Martin On Mon, Jul 5, 2010 at 4:33 PM, Martin wrote: > On 05/07/2010 19:48, Marcos Douglas wrote: >> >> We can to use methods of an object to create others objects, or this >> is a bad programming practice? >> eg: >> var >>   obj1, obj2: TmyObject; >> begin >>   obj1 := tobj1.create; //ok >>  

Re: [fpc-pascal] question about changing default ASCII table in the fpc 2.2.0 IDE

2010-07-05 Thread Tomas Hajny
On 25 Jun 10, at 8:07, Noel and Marie wrote: Hi Noel, > Thanks Tomas. I didn't see your promise to look at the problem. Sorry, it took somewhat longer, but the results are here: 1) It works as expected if _not_ using unit Crt. 2) There is a bug in implementation of unit Crt for Windows. This

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Marcos Douglas
On Mon, Jul 5, 2010 at 4:07 PM, spir wrote: > On Mon, 5 Jul 2010 15:48:40 -0300 > Marcos Douglas wrote: > > Questions of style: just a personal opinion. > >> We can to use methods of an object to create others objects, or this >> is a bad programming practice? >> eg: >> var >>   obj1, obj2: TmyOb

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Martin
On 05/07/2010 19:48, Marcos Douglas wrote: We can to use methods of an object to create others objects, or this is a bad programming practice? eg: var obj1, obj2: TmyObject; begin obj1 := tobj1.create; //ok obj2 := obj1.createObj; // is this recommended? This is used very often like

Re: [fpc-pascal] methods of an object to create others objects

2010-07-05 Thread spir
On Mon, 5 Jul 2010 15:48:40 -0300 Marcos Douglas wrote: Questions of style: just a personal opinion. > We can to use methods of an object to create others objects, or this > is a bad programming practice? > eg: > var > obj1, obj2: TmyObject; > begin > obj1 := tobj1.create; //ok > obj2 := o

[fpc-pascal] methods of an object to create others objects

2010-07-05 Thread Marcos Douglas
We can to use methods of an object to create others objects, or this is a bad programming practice? eg: var obj1, obj2: TmyObject; begin obj1 := tobj1.create; //ok obj2 := obj1.createObj; // is this recommended? try //... finally obj1.free; obj2.free; end; end; Why I ask this