Quick Modern Object Pascal Introduction, for Programmers

classic Classic list List threaded Threaded
32 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Quick Modern Object Pascal Introduction, for Programmers

Michalis Kamburelis-3
Hi,

So, I wrote a document describing (quickly!) many features of the
modern Object Pascal:)

Read on:

http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html

http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.pdf

This document started just Thursday morning. I thought that such
document would be a helpful resource for the developers interested in
my Castle Game Engine (http://castle-engine.sourceforge.net/ ). The
document is directed at programmers who already know the concepts
(like classes, virtual methods) but they don't know how they look like
in Object Pascal. Or maybe they know Object Pascal classes, but don't
know about some "advanced" (but really useful IMHO) language features
added in the recent years. For example, many people are not aware that
Pascal has generics -- a powerful and important language feature,
IMHO. Many people are not sure what happens when an exception occurs
during the constructor -- which is quite important to know, if you
want to write correct destructors, I think.

This document quickly grew over the last 3 days:) It starts from
really basic stuff, and quite quickly jumps into "advanced" stuff. The
PDF is now 52-pages long, and calling it a "Quick Introduction"
becomes harder and harder:)

Parts of it apply only to recent FPC versions, and only to {$mode
objfpc} mode. I deliberately didn't want to burden the reader with
historic details, or differences between Delphi and FPC, or FPC
$modes. This is for readers who just use the latest FPC version, as
their primary Pascal compiler, and want to use the language with all
it's current features.

Share and redistribute as you like. The source is in AsciiDoc,
available on GitHub
https://github.com/michaliskambi/modern-pascal-introduction , and
corrections and improvements and all comments are very much welcome!
You're also welcome to reuse parts of it for FPC/Lazarus wiki or any
other document (license is the same as wikipedia). I hope you will
find this useful:)

Regards,
Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Quick Modern Object Pascal Introduction, for Programmers

Sandro Cumerlato

Thank you Michalis,
I really appreciated your work.

Well done!

Sandro Cumerlato


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Quick Modern Object Pascal Introduction, for Programmers

Dennis Poon
In reply to this post by Michalis Kamburelis-3


Michalis Kamburelis wrote:
Good work and thank you for your contribution to the community.

Dennis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Bls: Quick Modern Object Pascal Introduction, for Programmers

Mr Bee
In reply to this post by Michalis Kamburelis-3
Good work, sir. Thank you very much. I might use your article to direct people who still thinks Pascal today is still like the old Pascal of the 70's. :) 

I have a little suggestion though. I prefer to use {$J-} directive in my Pascal program. I think it encourages good programming practice in Pascal. The {$J-} means constant is a constant no matter how you declare it. To bad FPC is still using {$J+} as the default even in the {$MODE OBJFPC}, which means a constant becomes a variable once you include the data type eventhough it's declared within a 'const' block. CMIIW.


Regards,

–Mr Bee



Pada Minggu, 19 Juni 2016 13:27, Michalis Kamburelis <[hidden email]> menulis:


Hi,

So, I wrote a document describing (quickly!) many features of the
modern Object Pascal:)

Read on:

http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html

http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.pdf

This document started just Thursday morning. I thought that such
document would be a helpful resource for the developers interested in
my Castle Game Engine (http://castle-engine.sourceforge.net/ ). The
document is directed at programmers who already know the concepts
(like classes, virtual methods) but they don't know how they look like
in Object Pascal. Or maybe they know Object Pascal classes, but don't
know about some "advanced" (but really useful IMHO) language features
added in the recent years. For example, many people are not aware that
Pascal has generics -- a powerful and important language feature,
IMHO. Many people are not sure what happens when an exception occurs
during the constructor -- which is quite important to know, if you
want to write correct destructors, I think.

This document quickly grew over the last 3 days:) It starts from
really basic stuff, and quite quickly jumps into "advanced" stuff. The
PDF is now 52-pages long, and calling it a "Quick Introduction"
becomes harder and harder:)

Parts of it apply only to recent FPC versions, and only to {$mode
objfpc} mode. I deliberately didn't want to burden the reader with
historic details, or differences between Delphi and FPC, or FPC
$modes. This is for readers who just use the latest FPC version, as
their primary Pascal compiler, and want to use the language with all
it's current features.

Share and redistribute as you like. The source is in AsciiDoc,
available on GitHub
https://github.com/michaliskambi/modern-pascal-introduction , and
corrections and improvements and all comments are very much welcome!
You're also welcome to reuse parts of it for FPC/Lazarus wiki or any
other document (license is the same as wikipedia). I hope you will
find this useful:)

Regards,
Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Quick Modern Object Pascal Introduction, for Programmers

Dennis Poon
In reply to this post by Michalis Kamburelis-3
May I suggest the addition of :
1) user defined operator?
2) use of ClassType function for cloning objects


Dennis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Quick Modern Object Pascal Introduction, for Programmers

Mark Morgan Lloyd-5
In reply to this post by Michalis Kamburelis-3
Michalis Kamburelis wrote:
Nicely done, a good practical approach

I'd suggest warning readers early about "dangling else", and using
otherwise  rather than  else  in the  case  examples.

A private online service I use has somebody who still bears the scars of
Olivetti attempting to write an operating system in (strict, unexpanded)
Pascal. I think that Turbo Pascal came along a bit after that, but by
then the damage was done.

It's unfortunate that there's a lot of C programmers who wouldn't dream
of writing in K&R, but who still assume that Pascal is still as
primitive as it was in the 1970s.

There's a few places where a native English author would have done
things a bit differently. For example, in most places "Castle Game
Engine" would probably be prefixed by "the", and also "it allows
[something, what] to deal with cases when simple class inheritance is
not enough".

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Quick Modern Object Pascal Introduction, for Programmers

Sven Barth-2

Am 20.06.2016 11:56 schrieb "Mark Morgan Lloyd" <[hidden email]>:
> There's a few places where a native English author would have done things a bit differently. For example, in most places "Castle Game Engine" would probably be prefixed by "the", and also "it allows [something, what] to deal with cases when simple class inheritance is not enough".

Michalis also provided a link to the source repo, so you can clone, correct such problems and issue a merge request.

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Quick Modern Object Pascal Introduction, for Programmers

Marcos Douglas B. Santos
In reply to this post by Michalis Kamburelis-3
On Sun, Jun 19, 2016 at 3:26 AM, Michalis Kamburelis
<[hidden email]> wrote:
Good job, thanks for share.
Don't agree with "Ugly (COM) interfaces". Yeah, _AddRef, _Release,
QueryInterface is ugly implementation but reference-counting mechanism
is nice.

Best regards,
Marcos Douglas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Bls: Quick Modern Object Pascal Introduction, for Programmers

Mr Bee
In reply to this post by Michalis Kamburelis-3
Good work, sir. Thank you very much. I might use your article to direct people who still thinks Pascal today is still like the old Pascal of the 70's. :) 

I have a little suggestion though. I prefer to use {$J-} directive in my Pascal program. I think it encourages good programming practice in Pascal. The {$J-} means constant is a constant no matter how you declare it. Too bad FPC is still using {$J+} as the default even in the {$MODE OBJFPC}, which means a constant becomes a variable once you include the data type eventhough it's declared within a 'const' block. CMIIW.

Regards,

–Mr Bee



Pada Minggu, 19 Juni 2016 13:27, Michalis Kamburelis <[hidden email]> menulis:


Hi,

So, I wrote a document describing (quickly!) many features of the
modern Object Pascal:)

Read on:

http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html

http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.pdf

This document started just Thursday morning. I thought that such
document would be a helpful resource for the developers interested in
my Castle Game Engine (http://castle-engine.sourceforge.net/ ). The
document is directed at programmers who already know the concepts
(like classes, virtual methods) but they don't know how they look like
in Object Pascal. Or maybe they know Object Pascal classes, but don't
know about some "advanced" (but really useful IMHO) language features
added in the recent years. For example, many people are not aware that
Pascal has generics -- a powerful and important language feature,
IMHO. Many people are not sure what happens when an exception occurs
during the constructor -- which is quite important to know, if you
want to write correct destructors, I think.

This document quickly grew over the last 3 days:) It starts from
really basic stuff, and quite quickly jumps into "advanced" stuff. The
PDF is now 52-pages long, and calling it a "Quick Introduction"
becomes harder and harder:)

Parts of it apply only to recent FPC versions, and only to {$mode
objfpc} mode. I deliberately didn't want to burden the reader with
historic details, or differences between Delphi and FPC, or FPC
$modes. This is for readers who just use the latest FPC version, as
their primary Pascal compiler, and want to use the language with all
it's current features.

Share and redistribute as you like. The source is in AsciiDoc,
available on GitHub
https://github.com/michaliskambi/modern-pascal-introduction , and
corrections and improvements and all comments are very much welcome!
You're also welcome to reuse parts of it for FPC/Lazarus wiki or any
other document (license is the same as wikipedia). I hope you will
find this useful:)

Regards,
Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Bls: Quick Modern Object Pascal Introduction, for Programmers

Michalis Kamburelis-3
In reply to this post by Mr Bee
2016-06-20 5:31 GMT+02:00 Mr Bee <[hidden email]>:
[...]
> I have a little suggestion though. I prefer to use {$J-} directive in my
> Pascal program. I think it encourages good programming practice in Pascal.
> The {$J-} means constant is a constant no matter how you declare it. To bad
> FPC is still using {$J+} as the default even in the {$MODE OBJFPC}, which
> means a constant becomes a variable once you include the data type
> eventhough it's declared within a 'const' block. CMIIW.
>

Ouch. For some reason, I thought that {$J-} is the default in {$mode
objfpc} since years, and we have left that mistake behind us. Quick
test showed me that I was mistaken. This makes a *lot* of my code less
safe that I assumed, as in many recent projects I didn't bother to
explicitly use {$J-}.

This is an excellent suggestion then, thank you. I updated the
document to encourage everywhere doing

  {$mode objfpc}{$H+}{$J-}

at the beginning.

I definitely *do not want* to explain to any new programmer what a
"writeable constant" is... This concept should remain buried:)

Regards,
Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Bls: Quick Modern Object Pascal Introduction, for Programmers

Marc Hanisch
Thanks Michalis for your excellent work! It's very important to left the early 90s associated with Pascal programming behind us and to encourage new developers to have a look onto the modern aspects of Object Pascal!

Maybe a little bit offtopic, but I have a question regarding the compiler directives: is there a way to tell Lazarus to use these directives in every new unit?

Best regards,
Marc

2016-06-21 7:47 GMT+02:00 Michalis Kamburelis <[hidden email]>:
2016-06-20 5:31 GMT+02:00 Mr Bee <[hidden email]>:
[...]
> I have a little suggestion though. I prefer to use {$J-} directive in my
> Pascal program. I think it encourages good programming practice in Pascal.
> The {$J-} means constant is a constant no matter how you declare it. To bad
> FPC is still using {$J+} as the default even in the {$MODE OBJFPC}, which
> means a constant becomes a variable once you include the data type
> eventhough it's declared within a 'const' block. CMIIW.
>

Ouch. For some reason, I thought that {$J-} is the default in {$mode
objfpc} since years, and we have left that mistake behind us. Quick
test showed me that I was mistaken. This makes a *lot* of my code less
safe that I assumed, as in many recent projects I didn't bother to
explicitly use {$J-}.

This is an excellent suggestion then, thank you. I updated the
document to encourage everywhere doing

  {$mode objfpc}{$H+}{$J-}

at the beginning.

I definitely *do not want* to explain to any new programmer what a
"writeable constant" is... This concept should remain buried:)

Regards,
Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers

Mr Bee
In reply to this post by Michalis Kamburelis-3
I definitely *do not want* to explain to any new programmer what a "writeable constant" is... This concept should remain buried :)
 
Exactly! I also don't understand why the {$MODE OBJFPC} uses the {$J+} as the default. :)


–Mr Bee



Pada Selasa, 21 Juni 2016 12:47, Michalis Kamburelis <[hidden email]> menulis:


2016-06-20 5:31 GMT+02:00 Mr Bee <[hidden email]>:
[...]
> I have a little suggestion though. I prefer to use {$J-} directive in my
> Pascal program. I think it encourages good programming practice in Pascal.
> The {$J-} means constant is a constant no matter how you declare it. To bad
> FPC is still using {$J+} as the default even in the {$MODE OBJFPC}, which
> means a constant becomes a variable once you include the data type
> eventhough it's declared within a 'const' block. CMIIW.
>

Ouch. For some reason, I thought that {$J-} is the default in {$mode
objfpc} since years, and we have left that mistake behind us. Quick
test showed me that I was mistaken. This makes a *lot* of my code less
safe that I assumed, as in many recent projects I didn't bother to
explicitly use {$J-}.

This is an excellent suggestion then, thank you. I updated the
document to encourage everywhere doing

  {$mode objfpc}{$H+}{$J-}

at the beginning.

I definitely *do not want* to explain to any new programmer what a
"writeable constant" is... This concept should remain buried:)


Regards,
Michalis



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers

Mr Bee
In reply to this post by Marc Hanisch
Maybe a little bit offtopic, but I have a question regarding the compiler directives: is there a way to tell Lazarus to use these directives in every new unit?
 
I even expect a bit further. These {$MODE OBJFPC}, {$H+}, and {$J-} directives should be the *default* directives for every new FPC programs/units. We're now using Free Pascal compiler on 2016. Why do we need to explicitly declare Free Pascal mode in a Free Pascal program? In 21st century, our string should not be limited to 255 chars anymore. And what the hell is "writable constant"? It's contradictio in terminis. :)

If somehow someone want to deals with those things, let them use the appropriate directives explicitly. But for most programs we build today, those things should be the default.


–Mr Bee



Pada Selasa, 21 Juni 2016 13:15, Marc Hanisch <[hidden email]> menulis:


Thanks Michalis for your excellent work! It's very important to left the early 90s associated with Pascal programming behind us and to encourage new developers to have a look onto the modern aspects of Object Pascal!

Maybe a little bit offtopic, but I have a question regarding the compiler directives: is there a way to tell Lazarus to use these directives in every new unit?

Best regards,
Marc

2016-06-21 7:47 GMT+02:00 Michalis Kamburelis <[hidden email]>:
2016-06-20 5:31 GMT+02:00 Mr Bee <[hidden email]>:
[...]
> I have a little suggestion though. I prefer to use {$J-} directive in my
> Pascal program. I think it encourages good programming practice in Pascal.
> The {$J-} means constant is a constant no matter how you declare it. To bad
> FPC is still using {$J+} as the default even in the {$MODE OBJFPC}, which
> means a constant becomes a variable once you include the data type
> eventhough it's declared within a 'const' block. CMIIW.
>

Ouch. For some reason, I thought that {$J-} is the default in {$mode
objfpc} since years, and we have left that mistake behind us. Quick
test showed me that I was mistaken. This makes a *lot* of my code less
safe that I assumed, as in many recent projects I didn't bother to
explicitly use {$J-}.

This is an excellent suggestion then, thank you. I updated the
document to encourage everywhere doing

  {$mode objfpc}{$H+}{$J-}

at the beginning.

I definitely *do not want* to explain to any new programmer what a
"writeable constant" is... This concept should remain buried:)

Regards,
Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Quick Modern Object Pascal Introduction, for Programmers

Michalis Kamburelis-3
In reply to this post by Dennis Poon
2016-06-20 6:16 GMT+02:00 Dennis Poon <[hidden email]>:
> May I suggest the addition of :
> 1) user defined operator?

Added. I had it on my TODO list already:) See it here:
http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html#_operator_overloading
.

I documented also overriding operators for classes and records, and
mentioned the need for "class operator" on records to be able to work
with TFPGList and such.

> 2) use of ClassType function for cloning objects

I added two things:

- A section about TPersistent.Assign. This is the "basic approach to
cloning" that should probably be shown first. See it here:
http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html#_cloning_tpersistent_assign
. I mentioned the special rules when calling the "inherited" from
Assign overrides, and AssignTo, and the fact that TPersistent makes
the default visibility "published".

- And the ClassType, with the example of Clone method using it, is
added at the desciption of "class references" on
http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html#_class_references
.

Regards,
Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Quick Modern Object Pascal Introduction, for Programmers

Michalis Kamburelis-3
In reply to this post by Mark Morgan Lloyd-5
2016-06-20 11:44 GMT+02:00 Mark Morgan Lloyd
<[hidden email]>:
[...]
> I'd suggest warning readers early about "dangling else", and using otherwise
> rather than  else  in the  case  examples.

As for dangling else - good idea, I added a text and example
mentioning it briefly at the of
http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html#_testing_if
.

As for "otherwise" in "case" - I admit I prefer the "else" keyword
there. Although I don't have any other argument for it than being
accustomed to it, from reading existing sources. I just grepped FPC
and Lazarus source code, and I couldn't find any "case" with
"otherwise" section... while I easily found occurrences of "case" with
"else" sections.

For this reason, I am inclined to keep the example with "case ..
else", not "case .. otherwise". Indeed, one needs to be more careful
then (to not mix the "else" with an "if" from the last statement).

> It's unfortunate that there's a lot of C programmers who wouldn't dream of
> writing in K&R, but who still assume that Pascal is still as primitive as it
> was in the 1970s.

That's a great analogy. I may steal it some day:)

>
> There's a few places where a native English author would have done things a
> bit differently. For example, in most places "Castle Game Engine" would
> probably be prefixed by "the", and also "it allows [something, what] to deal
> with cases when simple class inheritance is not enough".
>

Thanks! I improved it a bit, adding "the" at some places and changed
to sentence to simpler "Useful when a simple class inheritance is not
enough.".

I'm not a native English speaker, so any corrections and suggestions
are very welcome when it comes to the language (and everything else:)

Regards,
Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Quick Modern Object Pascal Introduction, for Programmers

Michalis Kamburelis-3
In reply to this post by Marcos Douglas B. Santos
2016-06-20 14:30 GMT+02:00 Marcos Douglas <[hidden email]>:
> Don't agree with "Ugly (COM) interfaces". Yeah, _AddRef, _Release,
> QueryInterface is ugly implementation but reference-counting mechanism
> is nice.
>

Reference-counting is a useful concept, but "entangling" it with
interfaces is somewhat ugly IMHO. Those two concepts, and needs,
should be unrelated language features in my opinion:

- you use interfaces when you want to cast a class to multiple
possible interfaces,
- you use reference-counting to get automatic memory management (to
some extent, e.g. beware of cycles).

Both of these are useful, but forcing them together seems ugly. And it
causes actual problems:

- Various classes, using standard TComponent, have to "hack around"
reference counting by proving _AddRef implementations that do nothing,
- Even with hack above, you need to be extra careful about interface
temporary variables (you cannot free the class instance, if some
temporary interface variable may refer to it).

Regards,
Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Quick Modern Object Pascal Introduction, for Programmers

Dennis Poon
In reply to this post by Michalis Kamburelis-3

>> 2) use of ClassType function for cloning objects
> I added two things:
>
> - A section about TPersistent.Assign. This is the "basic approach to
> cloning" that should probably be shown first. See it here:
> http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html#_cloning_tpersistent_assign
> . I mentioned the special rules when calling the "inherited" from
> Assign overrides, and AssignTo, and the fact that TPersistent makes
> the default visibility "published".
>
> - And the ClassType, with the example of Clone method using it, is
> added at the desciption of "class references" on
> http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html#_class_references
>
Just read your example

|function TMyClass.Clone(AOwner: TComponent): TMyClass; begin // This
would always create an instance of exactly TMyClass: //Result :=
TMyClass.Create(AOwner); // This can potentially create an instance of
TMyClass descendant: Result := TMyClassRef(ClassType).Create(AOwner);
Result.Assign(Self); end |

|I remember someone once asked whether we should override the method
Assign or AssignTo.|
|I am worried, choosing the wrong method to override will produce
unexpected result.|
||
|Dennis|

||
|
|

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers

Sven Barth-2
In reply to this post by Mr Bee

Am 21.06.2016 08:58 schrieb "Mr Bee" <[hidden email]>:
>
> > Maybe a little bit offtopic, but I have a question regarding the compiler directives: is there a way to tell Lazarus to use these directives in every new unit?
>  
> I even expect a bit further. These {$MODE OBJFPC}, {$H+}, and {$J-} directives should be the *default* directives for every new FPC programs/units. We're now using Free Pascal compiler on 2016. Why do we need to explicitly declare Free Pascal mode in a Free Pascal program? In 21st century, our string should not be limited to 255 chars anymore. And what the hell is "writable constant"? It's contradictio in terminis. :)

We have a strong focus on backwards compatibility, so the default mode stays "fpc" and changing a modes' default settings would also affect backwards compatibility.

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers

Karoly Balogh (Charlie/SGR)
In reply to this post by Mr Bee
Hi,

On Tue, 21 Jun 2016, Mr Bee wrote:

> > Maybe a little bit offtopic, but I have a question regarding the
> >compiler directives: is there a way to tell Lazarus to use these
> >directives in every new unit?

No clue about Lazarus, but one can put -mOBJFPC in his compiler config
file (same with other modes), and tell Lazarus somehow to use that config
file. I'm positive that it's possible and that changes the default. Same
with a lot of other modeswitches or default-changers, if you don't wanna
pollute all your sources with such switches, put it in your config file.
Just don't forget to document these options for your project's build
system.

(And if you use components which expects other modes (Delphi is pretty
common), you might need to add the modeswitch to them instead...)

Charlie
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Bls: Quick Modern Object Pascal Introduction, for Programmers

Michalis Kamburelis-3
In reply to this post by Marc Hanisch
2016-06-21 8:15 GMT+02:00 Marc Hanisch <[hidden email]>:
> Thanks Michalis for your excellent work! It's very important to left the
> early 90s associated with Pascal programming behind us and to encourage new
> developers to have a look onto the modern aspects of Object Pascal!
>
> Maybe a little bit offtopic, but I have a question regarding the compiler
> directives: is there a way to tell Lazarus to use these directives in every
> new unit?
>

In Lazarus, you can choose the mode ("Object Pascal - default
(ObjFpc)") and $H+ ("Use AnsiStrings") in the Project -> Options ->
Compilation Options. This is equivalent to starting all your code with
"{$mode objfpc}{$H+}".

In fact, these are already the default: ObjFpc and $H+. So, if you're
using Lazarus for your development, these are already set at nice
default values.

It seems not possible to set the "{$writeableconst off}" (equivalent
to "{$J-}") using Lazarus options. Probably because it seems not
possible to do it using FPC command-line, so Lazarus would not have
how to communicate it to FPC. Seems like a simple omission, and a
bugreport to FPC would fix it:)

Regards,
Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
12