Marc Weustink | 1 May 2008 15:23
Favicon

Re: Pointers in Pascal!!

Mattias Gaertner wrote:
> On Wed, 30 Apr 2008 01:22:47 +0200
> Marc Weustink <marc@...> wrote:
> 
>> Alan Krause wrote:
>>> Hans MÃ¥rtensson wrote:
>>>> But that would not work after the pointer was used and then it's 
>>>> memory freed.
>>>> So a better way might be:
>>>>
>>>> Always when declaring pointers do it this way:
>>>>
>>>> var p:  ^sometype = nil;
>>>>
>>>> Then in stead of using the freemem, define your own procedure:
>>>>
>>>> procedure myfreemem(var p: pointer);
>>>> begin if p<>nil then begin freemem(p); p:=nil end end;
>>> Use FreeAndNil() -
>>>
>>> http://www.delphibasics.co.uk/RTL.asp?Name=FreeAndNil
>> FreeAndNil works only for classes, not for objects/record
> 
> ReAllocMem(p,0);

Ah, now I understand why you use them :)

Anyway does it set p:=nil ?

Marc
(Continue reading)

Mattias Gaertner | 1 May 2008 16:09
Picon
Favicon

Re: Pointers in Pascal!!

On Thu, 01 May 2008 15:23:29 +0200
Marc Weustink <marc@...> wrote:

> Mattias Gaertner wrote:
>[...]
> > ReAllocMem(p,0);
> 
> Ah, now I understand why you use them :)
> 
> Anyway does it set p:=nil ?

Yes.

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

Rainer Stratmann | 1 May 2008 16:24
Picon
Favicon

fpreaddir


fpreaddir
-> http://www.freepascal.org/docs-html/rtl/baseunix/fpreaddir.html

dirent record structure
-> http://www.freepascal.org/docs-html/rtl/baseunix/dirent.html

How do I know if the readed entry is a subdir?

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

Marco van de Voort | 1 May 2008 17:17
Picon
Favicon

Re: fpreaddir

> fpreaddir
> -> http://www.freepascal.org/docs-html/rtl/baseunix/fpreaddir.html
> 
> dirent record structure
> -> http://www.freepascal.org/docs-html/rtl/baseunix/dirent.html
> 
> How do I know if the readed entry is a subdir?

d_type being

  DT_UNKNOWN       0
  DT_FIFO          1
      DT_CHR           2
      DT_DIR           4
      DT_BLK           6
      DT_REG           8
      DT_LNK          10
      DT_SOCK         12
      DT_WHT          14

But why do you not simply use findfirst/findnext? It's more portable.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@...
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Rainer Stratmann | 1 May 2008 16:54
Picon
Favicon

Re: fpreaddir

Am Donnerstag, 1. Mai 2008 17:17 schrieb Marco van de Voort:
> d_type being
>
>   DT_UNKNOWN       0
>   DT_FIFO          1
>       DT_CHR           2
>       DT_DIR           4
>       DT_BLK           6
>       DT_REG           8
>       DT_LNK          10
>       DT_SOCK         12
>       DT_WHT          14
>
> But why do you not simply use findfirst/findnext? It's more portable.

The result of d_type is always 0 even if the entry is a directory.

Your question is not easy to answer.
In one way you are right, but I like to program as close to the os as 
possible.
Does findfirst/findnext also support these things like '*.pas' and file 
attributes?
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@...
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Marco van de Voort | 1 May 2008 17:34
Picon
Favicon

Re: fpreaddir

> Am Donnerstag, 1. Mai 2008 17:17 schrieb Marco van de Voort:
> >       DT_LNK          10
> >       DT_SOCK         12
> >       DT_WHT          14
> >
> > But why do you not simply use findfirst/findnext? It's more portable.
> 
> The result of d_type is always 0 even if the entry is a directory.

Then you'll have to do a fpstat to get additional data.

> Your question is not easy to answer. In one way you are right, but I like
> to program as close to the os as possible.

In general findfirst/findnext is ok, unless you are creating e.g. an unix
specific backup application that touches hundreds of thousands of files.

> Does findfirst/findnext also support these things like '*.pas' and file 
> attributes?

It supports wildcards. The file attributes are limited to the ones in
searchrec, see help for more info.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@...
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Marc Santhoff | 1 May 2008 18:58
Picon
Favicon

Re: fpreaddir

Am Donnerstag, den 01.05.2008, 16:54 +0200 schrieb Rainer Stratmann:
> Am Donnerstag, 1. Mai 2008 17:17 schrieb Marco van de Voort:
> > d_type being
> >
> >   DT_UNKNOWN       0
> >   DT_FIFO          1
> >       DT_CHR           2
> >       DT_DIR           4
> >       DT_BLK           6
> >       DT_REG           8
> >       DT_LNK          10
> >       DT_SOCK         12
> >       DT_WHT          14
> >
> > But why do you not simply use findfirst/findnext? It's more portable.
> 
> The result of d_type is always 0 even if the entry is a directory.

What os are you on?

I did "man readdir" and "man dirent" and found enough information. One
bit from the dirent manpage:

BUGS
     The usage of the member d_type of struct dirent is unportable as it is
     FreeBSD-specific.  It also may fail on certain filesystems, for example
     the cd9660 filesystem.

Maybe that's hitting you ...

(Continue reading)

Rainer Stratmann | 1 May 2008 18:53
Picon
Favicon

Re: fpreaddir

Am Donnerstag, 1. Mai 2008 18:58 schrieb Marc Santhoff:
> What os are you on?
Knoppix last DVD from heise
> I did "man readdir" and "man dirent" and found enough information. One
> bit from the dirent manpage:
I did it also

...
Other  than  Linux,  the d_type field is available mainly only on BSD systems.  
This field makes it possible to avoid the expense of calling
       stat() if further actions depend on the type of the file.
...

So I will use stat.

> BUGS
>      The usage of the member d_type of struct dirent is unportable as it is
>      FreeBSD-specific.  It also may fail on certain filesystems, for
> example the cd9660 filesystem.
>
> Maybe that's hitting you ...
>
> HTH,
> Marc
>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal@...
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
(Continue reading)

Damien Gerard | 5 May 2008 12:06

Pointer address into string


Hi !

I would like to display in a lazarus application the address of a  
pointer.
For this, I use :

var s: string;
    p:pointer;
[...]
s := IntToStr(PtrInt(p))

However, I've got a warning (hint) from the compiler :
Conversion between ordinals and pointers is not portable

What is the way to do this ?

--
Damien Gerard
milipili@...

"Intelligence is 10 million rules."
    -- Douglas Lenat

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

Damien Gerard | 4 May 2008 18:21

Pointer address into string


Hi !

I would like to display in a lazarus application the address of a  
pointer.
For this, I use :

var s: string;
     p:pointer;
[...]
s := IntToStr(PtrInt(p))

However, I've got a warning (hint) from the compiler :
Conversion between ordinals and pointers is not portable

What is the way to do this ?

--
Damien Gerard
milipili@...

"Intelligence is 10 million rules."
    -- Douglas Lenat

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


Gmane