Re: [fpc-pascal] PChar & AnsiString -- for-in loop enumerator

2010-06-02 Thread Bee Jay
On 2 Jun 2010, at 20:09, spir wrote: >> http://wiki.freepascal.org/for-in_loop > > Is this implemented? (unable to make it work -- the compiler refuses the > for...in notation) AFAIK, yes. At least, I know it's already in trunk since a while ago. Never use it myself though. -Bee- __

Re: [fpc-pascal] PChar & AnsiString

2010-06-02 Thread spir
On Wed, 2 Jun 2010 14:30:15 +0200 Graeme Geldenhuys wrote: > On 2 June 2010 14:16, Marco van de Voort wrote: > > > > Afaik it is merged into 2.4.1 already. > > > Did somebody actually test it other than Paul (that also implemented > it)? If so, that was a rather quick test for a big compiler c

Re: [fpc-pascal] PChar & AnsiString -- for-in loop enumerator

2010-06-02 Thread spir
On Wed, 2 Jun 2010 15:19:55 +0700 Bee Jay wrote: > On 1 Jun 2010, at 22:13, spir ☣ wrote: > > > (*) And to some more constructs in other languages, like foreach (*the* > > feature I miss in freepascal): > > foreach name in names do ... end; > > http://wiki.freepascal.org/for-in_loop Is this

Re: [fpc-pascal] PChar & AnsiString

2010-06-02 Thread Michael Van Canneyt
On Wed, 2 Jun 2010, Marco van de Voort wrote: In our previous episode, Michael Van Canneyt said: http://wiki.freepascal.org/for-in_loop -Bee- Great! Thank you very much. (Is this feature mentionned in "official" docs? how could I miss it? The ref guide only mentions "The For..to/downto..

Re: [fpc-pascal] PChar & AnsiString

2010-06-02 Thread Graeme Geldenhuys
On 2 June 2010 14:16, Marco van de Voort wrote: > > Afaik it is merged into 2.4.1 already. Did somebody actually test it other than Paul (that also implemented it)? If so, that was a rather quick test for a big compiler change. -- Regards, - Graeme - __

Re: [fpc-pascal] PChar & AnsiString

2010-06-02 Thread Marco van de Voort
In our previous episode, Michael Van Canneyt said: > >> > >> http://wiki.freepascal.org/for-in_loop > >> > >> -Bee- > > > > Great! Thank you very much. (Is this feature mentionned in "official" docs? > > how could I miss it? The ref guide only mentions "The For..to/downto..do > > statement", I gu

Re: [fpc-pascal] PChar & AnsiString

2010-06-02 Thread Michael Van Canneyt
On Wed, 2 Jun 2010, spir wrote: On Wed, 2 Jun 2010 15:19:55 +0700 Bee Jay wrote: On 1 Jun 2010, at 22:13, spir ☣ wrote: (*) And to some more constructs in other languages, like foreach (*the* feature I miss in freepascal): foreach name in names do ... end; http://wiki.freepascal.org/

Re: [fpc-pascal] PChar & AnsiString

2010-06-02 Thread Graeme Geldenhuys
On 2 June 2010 12:39, spir wrote: > > Great! Thank you very much. (Is this feature mentionned in "official" docs? > how could I miss it? The ref guide only mentions "The For..to/downto..do > statement", I guess.) > I don't think it's in FPC 2.4.1 either, only Trunk (2.5.1) - so no, the current

Re: [fpc-pascal] PChar & AnsiString

2010-06-02 Thread spir
On Wed, 2 Jun 2010 15:19:55 +0700 Bee Jay wrote: > On 1 Jun 2010, at 22:13, spir ☣ wrote: > > > (*) And to some more constructs in other languages, like foreach (*the* > > feature I miss in freepascal): > > foreach name in names do ... end; > > http://wiki.freepascal.org/for-in_loop > > -Be

Re: [fpc-pascal] PChar & AnsiString

2010-06-02 Thread Bee Jay
On 1 Jun 2010, at 22:13, spir ☣ wrote: > (*) And to some more constructs in other languages, like foreach (*the* > feature I miss in freepascal): > foreach name in names do ... end; http://wiki.freepascal.org/for-in_loop -Bee- ___ fpc-pascal mailli

Re: [fpc-pascal] PChar & AnsiString

2010-06-01 Thread David Emerson
> > >> This is not correct. Many strings are simply referenced several > > >> times. > > > > > > May I ask in which typical cases? In an earlier version of our database (before we had things properly typed) many things were stored as strings. Thus a common ansistring may have had a reference

Re: [fpc-pascal] PChar & AnsiString

2010-06-01 Thread spir
On Tue, 01 Jun 2010 16:30:22 +0100 Martin wrote: > I don't know all the internals of FPC, but yes to my understanding, your > quote: >"parameter passing is just an implicit assignment" > is absolutely true. > > So why do you then say "copy on write" would not apply? > The assignment creates

Re: [fpc-pascal] PChar & AnsiString

2010-06-01 Thread Martin
On 01/06/2010 16:13, spir ☣ wrote: On Tue, 01 Jun 2010 15:00:47 +0100 Martin wrote: On 01/06/2010 11:23, spir ☣ wrote: What is the actual benefit of copy-on-write? I ask because of the following reasoning: * If a string is just used at several places, for example in output or into

Re: [fpc-pascal] PChar & AnsiString

2010-06-01 Thread spir ☣
On Tue, 1 Jun 2010 14:36:36 +0200 Jonas Maebe wrote: > > On 01 Jun 2010, at 14:28, spir ☣ wrote: > > > On Tue, 1 Jun 2010 13:05:16 +0200 (CEST) > > Michael Van Canneyt wrote: > > > >> This is not correct. Many strings are simply referenced several > >> times. > > > > May I ask in which typic

Re: [fpc-pascal] PChar & AnsiString

2010-06-01 Thread spir ☣
On Tue, 01 Jun 2010 15:00:47 +0100 Martin wrote: > On 01/06/2010 11:23, spir ☣ wrote: > > What is the actual benefit of copy-on-write? I ask because of the following > > reasoning: > > * If a string is just used at several places, for example in output or into > > bigger strings, then there is

Re: [fpc-pascal] PChar & AnsiString

2010-06-01 Thread Martin
On 01/06/2010 11:23, spir ☣ wrote: What is the actual benefit of copy-on-write? I ask because of the following reasoning: * If a string is just used at several places, for example in output or into bigger strings, then there is no reason reason to copy it into a new variable. * If a programmer

Re: [fpc-pascal] PChar & AnsiString

2010-06-01 Thread Jonas Maebe
On 01 Jun 2010, at 14:28, spir ☣ wrote: On Tue, 1 Jun 2010 13:05:16 +0200 (CEST) Michael Van Canneyt wrote: This is not correct. Many strings are simply referenced several times. May I ask in which typical cases? The most common one is probably assigning a function result to a variabl

Re: [fpc-pascal] PChar & AnsiString

2010-06-01 Thread spir ☣
On Tue, 1 Jun 2010 13:05:16 +0200 (CEST) Michael Van Canneyt wrote: [...] Thank you for all answers (all is now clear for me :-). > > * If a programmer explicitely assigns an existing string to a new variable, > > the intent is precisely copy-semantics, to make them independent for > > furthe

Re: [fpc-pascal] PChar & AnsiString

2010-06-01 Thread Michael Van Canneyt
On Tue, 1 Jun 2010, spir ☣ wrote: Hello, The documentation in the ref manual about PChar may have i bit more details: http://www.freepascal.org/docs-html/ref/refsu13.html#x36-390003.2.7 Do the following statements hold true? * This type is mainly intended to interface with C code (or for l

Re: [fpc-pascal] PChar & AnsiString

2010-06-01 Thread Felipe Monteiro de Carvalho
2010/6/1 spir ☣ : > * Like C strings, and unlike AnsiString-s (even if the latter also are > "pointed") Sure if you cast an AnsiString to a PChar it will only go until the first #0. You can't magically add capabilities to the PChar type. > * How is length computed (traversal?)? It isn't compute

[fpc-pascal] PChar & AnsiString

2010-06-01 Thread spir ☣
Hello, The documentation in the ref manual about PChar may have i bit more details: http://www.freepascal.org/docs-html/ref/refsu13.html#x36-390003.2.7 Do the following statements hold true? * This type is mainly intended to interface with C code (or for low-level needs?). Else AnsiString shou

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Graeme Geldenhuys
On 29/10/2009, Marco van de Voort wrote: > > > No, probably mixed sysutils and strings(?) use. pstring is defined in both > TP and Delphi. Once to short, once to ansistring That that must be FPC that is getting confused. In Lazurus I when "Project > New > Free Pascal application". That's as bas

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Marco van de Voort
In our previous episode, Henry Vermaak said: > > > > Trying what you suggested, I get the following compiler error. > > > > project1.lpr(20,11) Error: Incompatible types: got "PString" expected > > "PChar" > > This is probably dependant on compiler modes? No, probably mixed sysutils and strings(

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Graeme Geldenhuys
2009/10/29 Mattias Gaertner : > > I hope you mean {$mode objfpc}{$H+} :-) Yes. -- Regards, - Graeme - ___ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ ___ fpc-pasc

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Mattias Gaertner
On Thu, 29 Oct 2009 16:42:23 +0200 Graeme Geldenhuys wrote: > 2009/10/29 Mattias Gaertner : > > > > It compiles here. Probably you use some special units. > > Weird... As I mentioned, I'm using FPC 2.3.1 (64bit) under Linux and > $mode objfpc. I hope you mean {$mode objfpc}{$H+} Mattias

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Graeme Geldenhuys
2009/10/29 Mattias Gaertner : > > It compiles here. Probably you use some special units. Weird... As I mentioned, I'm using FPC 2.3.1 (64bit) under Linux and $mode objfpc. > > Graeme, why don't you just change the type of 'Text' to string? That's the plan - eventually. But the code is large and

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Graeme Geldenhuys
2009/10/29 Henry Vermaak : > > This is probably dependant on compiler modes? I'm using: $mode objfpc > You may have to do it like this: > > StrDispose(Text); > Text := StrAlloc(length(s) + 1); > StrPCopy(Text, s); Ah, now it works plus no memory leaks. Thanks! :-) Wow, something as simple as

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Henry Vermaak
2009/10/29 Graeme Geldenhuys : > On 29/10/2009, Mattias Gaertner wrote: >> >> >> Text:=strnew(PChar(s)); > > You read my mind. I was going to ask if it's ok to cast a PString to a PChar. > > Trying what you suggested, I get the following compiler error. > > project1.lpr(20,11) Error: Incompatible

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Mattias Gaertner
On Thu, 29 Oct 2009 15:44:09 +0200 Graeme Geldenhuys wrote: > On 29/10/2009, Mattias Gaertner wrote: > > > > > > Text:=strnew(PChar(s)); > > You read my mind. I was going to ask if it's ok to cast a PString to > a PChar. Yes. But it will not change the reference count. > Trying what you sugg

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Graeme Geldenhuys
On 29/10/2009, Mattias Gaertner wrote: > > > Text:=strnew(PChar(s)); You read my mind. I was going to ask if it's ok to cast a PString to a PChar. Trying what you suggested, I get the following compiler error. project1.lpr(20,11) Error: Incompatible types: got "PString" expected "PChar" Changi

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Mattias Gaertner
On Thu, 29 Oct 2009 13:20:42 + Henry Vermaak wrote: > 2009/10/29 Mattias Gaertner : > > On Thu, 29 Oct 2009 15:00:53 +0200 > > Graeme Geldenhuys wrote: > > > >> Hi, > >> > >> Do I create a memory leak if I cast a PChar it a AnsiString. Then > >> append text to the AnsiString and then cast it

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Henry Vermaak
2009/10/29 Mattias Gaertner : > On Thu, 29 Oct 2009 15:00:53 +0200 > Graeme Geldenhuys wrote: > >> Hi, >> >> Do I create a memory leak if I cast a PChar it a AnsiString. Then >> append text to the AnsiString and then cast it back to the original >> PChar? >> >> eg: >> var >>   Text: Pchar;    <--

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Mattias Gaertner
On Thu, 29 Oct 2009 15:00:53 +0200 Graeme Geldenhuys wrote: > Hi, > > Do I create a memory leak if I cast a PChar it a AnsiString. Then > append text to the AnsiString and then cast it back to the original > PChar? > > eg: > var > Text: Pchar;<-- global var containing text. > > procedure

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Henry Vermaak
2009/10/29 Graeme Geldenhuys : > Hi, > > Do I create a memory leak if I cast a PChar it a AnsiString. Then > append text to the AnsiString and then cast it back to the original > PChar? > > eg: > var >  Text: Pchar;    <-- global var containing text. > > procedure AppendText(const AText: string); >

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Martin Schreiber
On Thursday 29 October 2009 14:00:53 Graeme Geldenhuys wrote: > Hi, > > Do I create a memory leak if I cast a PChar it a AnsiString. Then > append text to the AnsiString and then cast it back to the original > PChar? > > eg: > var > Text: Pchar;<-- global var containing text. > > procedure Ap

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Martin
Graeme Geldenhuys wrote: Hi, Do I create a memory leak if I cast a PChar it a AnsiString. Then append text to the AnsiString and then cast it back to the original PChar? eg: var Text: Pchar;<-- global var containing text. procedure AppendText(const AText: string); var s: string; begin

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Mattias Gaertner
On Thu, 29 Oct 2009 15:00:53 +0200 Graeme Geldenhuys wrote: > Hi, > > Do I create a memory leak if I cast a PChar it a AnsiString. Then > append text to the AnsiString and then cast it back to the original > PChar? > > eg: > var > Text: Pchar;<-- global var containing text. > > procedure

Re: [fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Aleksa Todorovic
On Thu, Oct 29, 2009 at 14:00, Graeme Geldenhuys wrote: > Hi, > > Do I create a memory leak if I cast a PChar it a AnsiString. Then > append text to the AnsiString and then cast it back to the original > PChar? > > eg: > var >  Text: Pchar;    <-- global var containing text. > > procedure AppendTe

[fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

2009-10-29 Thread Graeme Geldenhuys
Hi, Do I create a memory leak if I cast a PChar it a AnsiString. Then append text to the AnsiString and then cast it back to the original PChar? eg: var Text: Pchar;<-- global var containing text. procedure AppendText(const AText: string); var s: string; begin s := Text + AText; Text