[fpc-pascal] TObjectList works; TFPObjectList gives memory leaks

2010-08-01 Thread Jim
Hi all,

Still working on my file indexer:
http://bitbucket.org/jb/flocate/changeset/6c6fa90e632e

Each search for files creates a TObjectList descendant
(TDirectoryEntryList, see directoryentrylist.pp)

On finding a file, the search class createa a DirectoryEntry object with
the relevant file properties and adds this to the directoryentrylist.

Finally, I iterate through the list and store the results in a database.
Then I try to destroy the directoryentrylist, and the directoryentry
items get deleted by the Tobjectlist code.

This works using a TObjectList; however when I use a TFPObjectList for
TDirectoryEntryList, I have a memory leak of exactly all files/objects
found that were not released.
(This is in FPC 2.5.1/Win32)

Am I missing something here? The documentation suggests that TObjectList
and TFPObjectlist only differ in some notification stuff...

Thanks,

-- 
Regards,

jb
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TObjectList works; TFPObjectList gives memory leaks

2010-08-01 Thread Marco van de Voort
In our previous episode, Jim said:
> 
> Still working on my file indexer:
> http://bitbucket.org/jb/flocate/changeset/6c6fa90e632e

The question should be why tobjectlist works. Since you don't set the
"freeobjects" anywhere.

Call inherited create(true) in your constructor instead of just create().

It would be interesting if you could come up with a little program that
really shows the problem (e.g. a small program that changes behaviour if you
just prefix "fp").
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TObjectList works; TFPObjectList gives memory leaks

2010-08-01 Thread Marco van de Voort
In our previous episode, Marco van de Voort said:
> 
> Call inherited create(true) in your constructor instead of just create().

Hmm no, that is not it either, since the constructor is overloaded. Then a
small example program to test is really needed. If you can reproduce it,
please file a bug at http://bugs.freepascal.org
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Something like g_object_get() in Pascal?

2010-08-01 Thread Matthias Klumpp
Hello!
I have a record containing a set of variables. This record should now be
accessed from an application developed in C (through a shared library).
Because Pascal records are incompatible with C structs, I could write a
get_value() function for each value in the record, e.g. if I have:

TTestRec = record
 val1: String;
 val2: Integer;
end;

I would have to write functions like:
function testrec_get_val1(rec: TTestRec): String;
function testrec_get_val2(rec: TTestRec): Integer;

Now the record consists of a lot more than just two properties. The
GObject type system knows a much better way for accessing properties:
(refer to
http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-get
)
I just write the property name as string and add a pointer to the result
type:

int i;
g_object_get(testrec, "val2", &i, NULL);

Is there a possibility to get the same function in Pascal to? That I just
define one get_value() function which receives the property name as string
and outputs the value of it?
Thanks & kind regards
   Matthias

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TObjectList works; TFPObjectList gives memory leaks

2010-08-01 Thread Jim
On 1-8-2010 14:29, Marco van de Voort wrote:
> In our previous episode, Marco van de Voort said:
>>
>> Call inherited create(true) in your constructor instead of just create().
> 
> Hmm no, that is not it either, since the constructor is overloaded. Then a
> small example program to test is really needed. If you can reproduce it,
> please file a bug at http://bugs.freepascal.org
True; I also explicitly set the ownsobject property. Nothing changed.

I'll try and see what I can do and file a bug if I have something working...
(Of course, it could be my newb programming that's causing this, but
then I'm extraordinarily lucky that tobjectlist works ;)

-- 
Regards,

jb
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Something like g_object_get() in Pascal?

2010-08-01 Thread Bernd Kreuss
On 01.08.2010 14:45, Matthias Klumpp wrote:

> Because Pascal records are incompatible with C structs

how are they incompatible? It should be possible to define the same
record as a struct in C and for every struct in C it should be possible
to define the same as a record in Pascal. Then you could work with
pointers to these structs (or records).

The difficulty in your example might come from the fact that it involves
the usage of strings and pascal will handle strings a bit differently
than this is usually done in C.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Something like g_object_get() in Pascal?

2010-08-01 Thread Matthias Klumpp
On Sun, 01 Aug 2010 19:27:20 +0200, Bernd Kreuss 
wrote:
> On 01.08.2010 14:45, Matthias Klumpp wrote:
> 
>> Because Pascal records are incompatible with C structs
> 
> how are they incompatible? It should be possible to define the same
> record as a struct in C and for every struct in C it should be possible
> to define the same as a record in Pascal. Then you could work with
> pointers to these structs (or records).
It does not work here... If I access a PChar in C, I just get an empty
string or a wrong pointer.

> The difficulty in your example might come from the fact that it involves
> the usage of strings and pascal will handle strings a bit differently
> than this is usually done in C.
I use PChars instead of strings, so this can't cause the problems.
Anyway, if you say it works I'll do some tests with it to get it working.
Thanks!

 Matthias

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Something like g_object_get() in Pascal?

2010-08-01 Thread Matthias Klumpp
On Sun, 01 Aug 2010 19:57:28 +0200, Matthias Klumpp 
wrote:
> On Sun, 01 Aug 2010 19:27:20 +0200, Bernd Kreuss

> wrote:
>> On 01.08.2010 14:45, Matthias Klumpp wrote:
>> 
>>> Because Pascal records are incompatible with C structs
>> 
>> how are they incompatible? It should be possible to define the same
>> record as a struct in C and for every struct in C it should be possible
>> to define the same as a record in Pascal. Then you could work with
>> pointers to these structs (or records).
> It does not work here... If I access a PChar in C, I just get an empty
> string or a wrong pointer.
> 
>> The difficulty in your example might come from the fact that it
involves
>> the usage of strings and pascal will handle strings a bit differently
>> than this is usually done in C.
> I use PChars instead of strings, so this can't cause the problems.
> Anyway, if you say it works I'll do some tests with it to get it
working.
> Thanks!

Aah, I finally found the problem... It was a small bug in my C-code
generator.
Now everything is fine.


>  Matthias

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal