[fpc-pascal] FPC class syntax was extended to support delphi code

2010-01-13 Thread Paul Ishenin

Hello, FPC-Pascal users discussions

I want to notify you that fpc trunk has extensions for the class syntax.

Class can have now the next sections:

1. 'var' sections to start regular fields declaration. 'var' can be used 
after other sections and after methods
2. 'class var' sections to start static fields declaration. Fields 
delcared in the 'class var' section are static fields
3. 'type' sections to declare types local to a class. It is allowed now 
to declare nested classes too.

4. 'const' section to declare constants local to a class.
5. 'class property' - similar to regular property but works with static 
fields and methods


Some examples:
http://wiki.lazarus.freepascal.org/class_extensions_examples

Please test and report bugs found.

Best regards,
Paul Ishenin.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC class syntax was extended to support delphi code

2010-01-13 Thread dmitry boyarintsev
Are these features available for {$mode delphi} only?

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


[fpc-pascal] Need help to fix a bug

2010-01-13 Thread JoshyFun
Hello FPC-Pascal,

I wish to fix this bug http://bugs.freepascal.org/view.php?id=15460
but I had found serious problems to understand how data is structured
in the TBufIndex and descendant classes, specially the
TDoubleLinkedBufIndex.

Can somebody help me ? From TBufDataset.BuildIndex I think that:

PBufRecLinkItem.Next points to next record.
PBufRecLinkItem.Prior points to previous record.

Maybe PBufRecLinkItem points to the dataset item data ?

Which is supossed to be pointed by:

(AIndex as TDoubleLinkedBufIndex).FFirstRecBuf
(AIndex as TDoubleLinkedBufIndex).FLastRecBuf

The first and last item in the dataset ?

Also which is the meaning of this line:

(AIndex as TDoubleLinkedBufIndex).FLastRecBuf[(AIndex as 
TDoubleLinkedBufIndex).IndNr].next:=(AIndex as 
TDoubleLinkedBufIndex).FFirstRecBuf;

I'm completly lost in this piece of code, and I really need it as my
SQL fetches could take around 1 minute and reorder data is a must. I
know I can reissue the query with a different order but this will take
around 20 seconds again while doing it in local memory is a breeze.

PS: To check changes in FPC I'm launching a complete build (without
clean) but this process will take 2 minutes anyway. Is there a faster
way to correctly build only the affected package (in this case fcl-db)
?

-- 
Best regards,
 JoshyFun

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


Re: [fpc-pascal] FPC class syntax was extended to support delphi code

2010-01-13 Thread David Emerson
Thank you for this message! This stuff sounds really cool. In 
particular, I have been itching for class constants.

A few questions come to mind:

a. 'var' sections -- I assume that 'var' is optional when declaring 
fields that occur first (i.e. directly after "private", "public", etc)

b. What does "strict private" mean, as opposed to private without 
strict? (My best guess is that it would be accessible only within the 
methods+properties of that class within the unit, as opposed to being 
available anywhere in the same unit where the class is declared...???)

c. What is the purpose of a class method? It would seem to me that 
methods should do the same thing whether they are class methods or not. 
Traditional variables change from instance to instance, but methods do 
not vary between instances, as far as I know-- right?

d. What happens with inheritance?

d.1. wrt class constants and class vars-- are there separate "instances" 
(for lack of a better word) of these, one instance for each descendant? 
Or is the class var/const only stored once for the ancestor that 
declares it, and all descendants share that?

d.2. wrt class methods, can they be virtual? (This strikes me as being 
closely related to d.1)

I guess an example is in order for d:

type
  t_parent = class
  private
class var
  x : integer;
const
  c = 5;
  end;

  t_child = class (t_parent)
  private
const
  c = 7;  // can I do this?
  end;

If I change t_child.x will it change t_parent.x?

e. Is it available in {$mode objfpc}? (I hope I hope I hope)?

I'd love to test this stuff out, though I usually stick with release 
versions... perhaps this is what is needed for me to take the plunge! 
Either way, I'm looking forward to this being released. Great work.

Cheers,
David

On Wed 13 Jan 2010, Paul Ishenin wrote:
> Hello, FPC-Pascal users discussions
> 
> I want to notify you that fpc trunk has extensions for the class 
syntax.
> 
> Class can have now the next sections:
> 
> 1. 'var' sections to start regular fields declaration. 'var' can be 
used 
> after other sections and after methods
> 2. 'class var' sections to start static fields declaration. Fields 
> delcared in the 'class var' section are static fields
> 3. 'type' sections to declare types local to a class. It is allowed 
now 
> to declare nested classes too.
> 4. 'const' section to declare constants local to a class.
> 5. 'class property' - similar to regular property but works with 
static 
> fields and methods
> 
> Some examples:
> http://wiki.lazarus.freepascal.org/class_extensions_examples
> 
> Please test and report bugs found.
> 
> Best regards,
> Paul Ishenin.
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> 



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


Re: [fpc-pascal] FPC class syntax was extended to support delphi code

2010-01-13 Thread Doug Chamberlin

David Emerson wrote:
b. What does "strict private" mean, as opposed to private without 
strict? (My best guess is that it would be accessible only within the 
methods+properties of that class within the unit, as opposed to being 
available anywhere in the same unit where the class is declared...???)


In Delphi what you have described is exactly what strict private gives you.

c. What is the purpose of a class method? It would seem to me that 
methods should do the same thing whether they are class methods or not. 
Traditional variables change from instance to instance, but methods do 
not vary between instances, as far as I know-- right?


Class methods allow you to call the method without instantiating the 
class first. For example, Result := TMyClass.MyClassFunction;


--
Doug C.
-
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC class syntax was extended to support delphi code

2010-01-13 Thread David Emerson
Doug Chamberlin wrote:
> Class methods allow you to call the method without instantiating the 
> class first. For example, Result := TMyClass.MyClassFunction;

Oh, that is so cool! I suppose that probably means that class methods 
can only reference class variables/methods/properties.

Cheers,
David

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


Re: [fpc-pascal] FPC class syntax was extended to support delphi code

2010-01-13 Thread Doug Chamberlin

David Emerson wrote:

Doug Chamberlin wrote:
Class methods allow you to call the method without instantiating the 
class first. For example, Result := TMyClass.MyClassFunction;


Oh, that is so cool! I suppose that probably means that class methods 
can only reference class variables/methods/properties.


Yup!

Of course, there are pros and cons to all this. Our once simple, 
straightforward language is not littered with "convenience" features 
that are not necessary at all. For example, what is the big advantage of 
class methods over simple functions and procedures?


--
Doug C.
-
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC class syntax was extended to support delphi code

2010-01-13 Thread Anthony Walter
>
> Yup!
>
> Of course, there are pros and cons to all this. Our once simple,
> straightforward language is not littered with "convenience" features that
> are not necessary at all. For example, what is the big advantage of class
> methods over simple functions and procedures?
>

Class methods can be virtual and have access to other (perhpas protected)
class members of the class.

type
  TA = class
  public
class procedure Hello; virtual;
  end;

  TB = class(TA)
  public
class procedure Hello; override;
  end;

  TAClass = class of TA;

{ TA }

class procedure TA.Hello;
begin
  ShowMessage('Hello this is ' + ClassName); // see I can access ClassName
end;

{ TB }

class procedure TB.Hello;
begin
  inherited Hello;
  ShowMessage('A different message here');
end;

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
  SomeClass: TAClass;
begin
  SomeClass := TB;
  SomeClass.Hello;
end;
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] FPC class syntax was extended to support delphi code

2010-01-13 Thread Aleksa Todorovic
On Wed, Jan 13, 2010 at 19:13, David Emerson  wrote:
>
> d.2. wrt class methods, can they be virtual? (This strikes me as being
> closely related to d.1)
>

Definitely, yes! (and I believe that was available before class
vars/consts) I use this great feature for (de)serialization of
messages in my client/server communication:

  TMessage = class
  public
constructor Create; virtual;
class function GetCode: Word; virtual;
Code: Word;
...
  end;

constructor TMessage.Create;
begin
  Code := GetCode;
end;

So, when I want to create new message, I just call
TLoginMessage.Create or TChatMessage.Create or whatever (those classes
override GetCode, and everything works perfect).
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


RE: [fpc-pascal] FPC class syntax was extended to support delphi code

2010-01-13 Thread Cox, Stuart TRAN:EX
>-Original Message-
>From: fpc-pascal-boun...@lists.freepascal.org 
>[mailto:fpc-pascal-boun...@lists.freepascal.org] On Behalf Of Doug Chamberlin
>Sent: Wednesday, January 13, 2010 11:21 AM
>To: FPC-Pascal users discussions
>Subject: Re: [fpc-pascal] FPC class syntax was extended to support delphi code
>
>David Emerson wrote:
>> Doug Chamberlin wrote:
>>> Class methods allow you to call the method without instantiating the 
>>> class first. For example, Result := TMyClass.MyClassFunction;
>> 
>> Oh, that is so cool! I suppose that probably means that class methods 
>> can only reference class variables/methods/properties.
>
>Yup!
>
>Of course, there are pros and cons to all this. Our once simple, 
>straightforward language is not littered with "convenience" features 
>that are not necessary at all. For example, what is the big advantage of 
>class methods over simple functions and procedures?

Some operations (procedures/functions) just go naturally with Classes but don't 
belong to any particular instance of that class.  
An example might be calculating the area of overlap between two geographic 
polygons (instances of the class) where the function returning the overlap area 
is a class function rather than an instance function/method of either of the 
two polygons.  Contrived, but imaginable.

>-- 
>Doug C.
>-
>A: Because it messes up the order in which people normally read text.
>Q: Why is top-posting such a bad thing?
>A: Top-posting.
>Q: What is the most annoying thing in e-mail?
>___
>fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
>http://lists.freepascal.org/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] [OT] which editor - Vim and Exuberant Ctags?

2010-01-13 Thread johanns
On Sun, Jan 10, 2010 at 02:44:46PM +0100, Hans-Peter Suter wrote:
> I'm on a mac and use TextMate currently. As it doesn't jump between
> declaration and implementation and ist mac-only, I am looking for a
> replacement.
> 
> Is Emacs a good choice? Does it work well with FPC?

I do my Pascal development using GVim and tag files generated with
Exuberant Ctags.  I am underwhelmed by the support for Pascal as a
language relative to ones like the C languages that are tied to the
history of the Vi editor family.

Exuberant Ctags will generate a tag file for classic Pascal code, but
only stand-alone functions and procedures are supported.  There is no
support for generating tags for variables of any kind.  Also, there is
not support for object oriented Pascal.  This is what I mean by
stand-alone functions and procedures.  Any use of dot notation with
functions or procedures is ignored.  Better support for prioritizing
IMPLEMENTATION versus INTERFACE sections would also be a plus.

Anyone know of any better options for navigating Pascal source code from
a classic or general purpose programmer's text editor?  Ideal would be a
better way of generating tag files.  I don't suppose anyone has
considered getting Cscope to work with Pascal source code?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC class syntax was extended to support delphi code

2010-01-13 Thread Paul Ishenin

dmitry boyarintsev wrote:

Are these features available for {$mode delphi} only?
  

No. For objfpc too.

Best regards,
Paul Ishenin.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC class syntax was extended to support delphi code

2010-01-13 Thread Doug Chamberlin

Cox, Stuart TRAN:EX wrote:
Some operations (procedures/functions) just go naturally with Classes but don't belong to any particular instance of that class.  
An example might be calculating the area of overlap between two geographic polygons (instances of the class) where the function returning the overlap area is a class function rather than an instance function/method of either of the two polygons.  Contrived, but imaginable.


Oh, I can imagine such methods also. And I've used them before. I just 
don't see the big advantage over having them be global 
functions/procedures located in the same unit as the class they operate 
on. So, as often as not, I go and create the global functions instead. 
Never could decide either way to go.


--
Doug C.
-
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC class syntax was extended to support delphi code

2010-01-13 Thread Paul Ishenin

David Emerson wrote:
a. 'var' sections -- I assume that 'var' is optional when declaring 
fields that occur first (i.e. directly after "private", "public", etc)
  

Yes.
b. What does "strict private" mean, as opposed to private without 
strict? (My best guess is that it would be accessible only within the 
methods+properties of that class within the unit, as opposed to being 
available anywhere in the same unit where the class is declared...???)
  
"strict private" is not a new feature. it means that something is 
private for this class only and can't be accessed by other classes or 
routines of the unit.
c. What is the purpose of a class method? It would seem to me that 
methods should do the same thing whether they are class methods or not. 
Traditional variables change from instance to instance, but methods do 
not vary between instances, as far as I know-- right?
  
Class method is not a new feature as well as static class method. Class 
method allows you to have methods which belongs to the class instead of 
an instance of the class. Class methods can be virtual. Static class 
methods can't.

d. What happens with inheritance?

d.1. wrt class constants and class vars-- are there separate "instances" 
(for lack of a better word) of these, one instance for each descendant? 
Or is the class var/const only stored once for the ancestor that 
declares it, and all descendants share that?
  
Class vars (static class fields) are stored only once for the class 
which declares them and all descendants share that.


Example:
TSomeClass = class
class var Value: Integer;
end;

TDescendant = class(TSomeClass);
begin
 TSomeClass.Value := 1;
 TDescendant.Value := 2;
 WriteLn(TSomeClass.Value); // this must output 2
end;

Class static field is not a new feature. But now you can declare them 
using 'class var' section after methods or 'type'/'const' section.
d.2. wrt class methods, can they be virtual? (This strikes me as being 
closely related to d.1)
  

class methods can be virtual. static class methods can't.

I guess an example is in order for d:

type
  t_parent = class
  private
class var
  x : integer;
const
  c = 5;
  end;

  t_child = class (t_parent)
  private
const
  c = 7;  // can I do this?
  end;
  
In ObjFpc mode you can't do this because t_child.c duplicates 
t_parent.c. In Delphi mode you can do this. I have no personal opinion 
how ObjFpc mode should work here but this behavior is consistent with 
restrictions for identifier duplication we currently have in objfpc mode.

e. Is it available in {$mode objfpc}? (I hope I hope I hope)?
  

yes.

Best regards,
Paul Ishenin.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Swopping two items in TCollection

2010-01-13 Thread Wimpie Nortje

Hi list

I have a class derived from Tcollection, holding items derived from 
TCollectionItem. How do I swop two items in the collection? FItem is of 
type TList which has an exchange function, but that is private and not 
accessable to me.



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