Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Zaher Dirkey
On Thu, Oct 14, 2010 at 11:21 AM, Michael Van Canneyt 
mich...@freepascal.org wrote:



 On Thu, 14 Oct 2010, Frank Church wrote:

  Can variables be declared within a begin end block?


 No.


That found in Gnu Pascal
Can we ask to be feature request?

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

RE: [fpc-pascal] TR: Strange Behaviour of TBits

2010-10-18 Thread Julien Devillers


-Message d'origine-
De : fpc-pascal-boun...@lists.freepascal.org 
[mailto:fpc-pascal-boun...@lists.freepascal.org] De la part de Jonas Maebe
Envoyé : vendredi 15 octobre 2010 11:11
À : FPC-Pascal users discussions
Objet : Re: [fpc-pascal] TR: Strange Behaviour of TBits


On 14 Oct 2010, at 17:24, Julien Devillers wrote:

 The above code returns 1, 2, 3, 3, 4 while it should return 1, 2, 3,  
 4, 5.

 I Built a TMyBits class using strictly the TBits.inc file from fpc  
 and... the bug does

 not appear... !

 I'm using lazarus 0.9.28.2 beta and fpc 2.2.4 with linux 64.

 Did I miss something ?

Your example works fine with FPC 2.4.0, try upgrading.


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

I did, it works now.
thanks
Julien
 

__ Information provenant d'ESET NOD32 Antivirus, version de la base des 
signatures de virus 5540 (20101017) __

Le message a été vérifié par ESET NOD32 Antivirus.

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


[fpc-pascal] IntList

2010-10-18 Thread Juha Manninen (gmail)
Hi

In Lazarus project jcf2 component has an IntList class which is poorly 
implemented. It depends on integer and pointer being the same size.
I will later suggest to replace it.

I have a better IntList. See:
  http://github.com/JuhaManninen/Pascal/blob/master/IntList/intlist.pas

It is similar to TStringList except that it works with integers.
It is well tested.

Question: can this class be added to FCL?
Clearly such class is needed sometimes and people must make their own versions 
of it. Generics can solve it in the future but it is not ready yet.

If it can't be included then I try to get it to Lazarus libraries.


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


Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Frank Church
On 18 October 2010 07:49, Florian Klaempfl flor...@freepascal.org wrote:

 Am 18.10.2010 08:17, schrieb Zaher Dirkey:
 
 
  On Thu, Oct 14, 2010 at 11:21 AM, Michael Van Canneyt
  mich...@freepascal.org mailto:mich...@freepascal.org wrote:
 
 
 
  On Thu, 14 Oct 2010, Frank Church wrote:
 
  Can variables be declared within a begin end block?
 
 
  No.
 


That is a rather emphatic no :).
 Is there some performance or other related reason why it is a bad idea? I'm
not knowledgeable in this area but I'd like to know.

Sometimes my variable declarations is filled with lots of variables for the
sake of making code involving long derived expressions comprehensible and
the clutter the understanding at the top level of the procedure.

Can a procedure be declared inline just for the sake of introducing those
variables?



 
  That found in Gnu Pascal
  Can we ask to be feature request?
 

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




-- 
Frank Church

===
http://devblog.brahmancreations.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] Re: Can variables be declared within a block?

2010-10-18 Thread Lukasz Sokol
On 18/10/2010 13:58, Frank Church wrote:
 On 18 October 2010 07:49, Florian Klaempfl flor...@freepascal.org wrote:
[...]
 No.


 
 That is a rather emphatic no :).
  Is there some performance or other related reason why it is a bad idea? I'm
 not knowledgeable in this area but I'd like to know.
 
 Sometimes my variable declarations is filled with lots of variables for the
 sake of making code involving long derived expressions comprehensible and
 the clutter the understanding at the top level of the procedure.
 
 Can a procedure be declared inline just for the sake of introducing those
 variables?
 
 
I guess it has something to do with 'functions/procedures not to be longer than
3 editor screens' and 'if it is longer and has more responsibilities than 
the name implies, do split it up' kind of paradigm.
c(-like) languages are very bad (don't keep you restrained) at this kind of use 
;)
and Gnu Pascal is a mere frontend to GCC so it may inherit c-isms ;)

Having variables declared within code block used to require to parse the source 
code
at least 2 times as opposed to nice Pascal way of doing it ONCE only. This was 
a compiler
performance winner in the times of ancient 286, 386 ;)
(dug out from depths of my memory, may be outdated badly).

L.

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


Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Florian Klaempfl
Am 18.10.2010 14:58, schrieb Frank Church:
 
 
 On 18 October 2010 07:49, Florian Klaempfl flor...@freepascal.org
 mailto:flor...@freepascal.org wrote:
 
 Am 18.10.2010 08:17, schrieb Zaher Dirkey:
 
 
  On Thu, Oct 14, 2010 at 11:21 AM, Michael Van Canneyt
  mich...@freepascal.org mailto:mich...@freepascal.org
 mailto:mich...@freepascal.org mailto:mich...@freepascal.org wrote:
 
 
 
  On Thu, 14 Oct 2010, Frank Church wrote:
 
  Can variables be declared within a begin end block?
 
 
  No.
 
 
 
 That is a rather emphatic no :).
  Is there some performance or other related reason why it is a bad idea?

It's just a matter of readability, e.g. having a variable declared in
two blocks with the same name can cause you a lot of headache:

procedure p;

begin
  ...
  begin
var i : integer;
...
...
...
i:=12341234;
...
...
...
...
  end;
  ...
  ...
  ...
  begin
var i : integer;
...
writeln(i); --- this i is not the same as above so i does not
contain 12341234 but it contains probably some garbage.
  end;
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Can variables be declared within a block?

2010-10-18 Thread Bernd Kreuss
On 18.10.2010 15:19, Lukasz Sokol wrote:

 Having variables declared within code block used to require to parse the 
 source code
 at least 2 times

Or create them on the stack at the begin and remove them at the end of
the block (which would be the only way to have some additional
functionality through this).

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


Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Frank Church
On 18 October 2010 14:42, Florian Klaempfl flor...@freepascal.org wrote:

 Am 18.10.2010 14:58, schrieb Frank Church:
 
 
  On 18 October 2010 07:49, Florian Klaempfl flor...@freepascal.org
  mailto:flor...@freepascal.org wrote:
 
  Am 18.10.2010 08:17, schrieb Zaher Dirkey:
  
  
   On Thu, Oct 14, 2010 at 11:21 AM, Michael Van Canneyt
   mich...@freepascal.org mailto:mich...@freepascal.org
  mailto:mich...@freepascal.org mailto:mich...@freepascal.org
 wrote:
  
  
  
   On Thu, 14 Oct 2010, Frank Church wrote:
  
   Can variables be declared within a begin end block?
  
  
   No.
  
 
 
  That is a rather emphatic no :).
   Is there some performance or other related reason why it is a bad idea?

 It's just a matter of readability, e.g. having a variable declared in
 two blocks with the same name can cause you a lot of headache:

 procedure p;

 begin
  ...
  begin
var i : integer;
...
...
...
i:=12341234;
...
...
...
...
  end;
  ...
  ...
  ...
  begin
var i : integer;
...
writeln(i); --- this i is not the same as above so i does not
 contain 12341234 but it contains probably some garbage.
  end;



My need is not for such kind or variables - it is for something like this.

say I have some thing like:
 StringList.NameOfIndex(TableName.FieldByName('').AsString) 
AnotherEqualLongExpression + SomeOtherEvenLongerExpression.

I just want to create shorter variables like
si :=  StringList.NameOfIndex(TableName.FieldByName('').AsString);
ae := xxx;
so:= yyy

to express complicated logic with them.

When I put them all at the top of the procedure, they are extra noise, which
is not necessary for the understanding the purpose at the top level of the
procedure.

I understand the need to avoid stuff that could create unintended errors and
have experienced such issues before. I will be careful not to use the more
than enough rope I have been given to hang myself. I promise :)


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




-- 
Frank Church

===
http://devblog.brahmancreations.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Frank Church
On 18 October 2010 14:55, Frank Church vfcli...@gmail.com wrote:



 On 18 October 2010 14:42, Florian Klaempfl flor...@freepascal.org wrote:

 Am 18.10.2010 14:58, schrieb Frank Church:
 
 
  On 18 October 2010 07:49, Florian Klaempfl flor...@freepascal.org
  mailto:flor...@freepascal.org wrote:
 
  Am 18.10.2010 08:17, schrieb Zaher Dirkey:
  
  
   On Thu, Oct 14, 2010 at 11:21 AM, Michael Van Canneyt
   mich...@freepascal.org mailto:mich...@freepascal.org
  mailto:mich...@freepascal.org mailto:mich...@freepascal.org
 wrote:
  
  
  
   On Thu, 14 Oct 2010, Frank Church wrote:
  
   Can variables be declared within a begin end block?
  
  
   No.
  
 
 
  That is a rather emphatic no :).
   Is there some performance or other related reason why it is a bad idea?

 It's just a matter of readability, e.g. having a variable declared in
 two blocks with the same name can cause you a lot of headache:

 procedure p;

 begin
  ...
  begin
var i : integer;
...
...
...
i:=12341234;
...
...
...
...
  end;
  ...
  ...
  ...
  begin
var i : integer;
...
writeln(i); --- this i is not the same as above so i does not
 contain 12341234 but it contains probably some garbage.
  end;



 My need is not for such kind or variables - it is for something like this.

 say I have some thing like:
  StringList.NameOfIndex(TableName.FieldByName('').AsString) 
 AnotherEqualLongExpression + SomeOtherEvenLongerExpression.

 I just want to create shorter variables like
 si :=  StringList.NameOfIndex(TableName.FieldByName('').AsString);
 ae := xxx;
 so:= yyy

 to express complicated logic with them.

 When I put them all at the top of the procedure, they are extra noise,
 which is not necessary for the understanding the purpose at the top level of
 the procedure.

 I understand the need to avoid stuff that could create unintended errors
 and have experienced such issues before. I will be careful not to use the
 more than enough rope I have been given to hang myself. I promise :)



I sometimes use nested procedures for such purposes when it comes to the
program logic itself, having something like that for variables would be
nice.

PS. The promise above should be we promise :)


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




 --
 Frank Church

 ===
 http://devblog.brahmancreations.com




-- 
Frank Church

===
http://devblog.brahmancreations.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Bernd Kreuss
On 18.10.2010 15:55, Frank Church wrote:

 I just want to create shorter variables like
 si :=  StringList.NameOfIndex(TableName.FieldByName('').AsString);
 ae := xxx;
 so:= yyy
 
 to express complicated logic with them.

Maybe the usage of WITH could be helpful in some of these cases

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


Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Bernd Kreuss
On 18.10.2010 15:55, Frank Church wrote:

 I understand the need to avoid stuff that could create unintended errors

It would create something that I would call irregularity (or even
ugliness) in the language grammar. Nowhere else is it ever allowed to
have certain things inside a begin/end block, type, const, var are all
only allowed in the *same* certain places outside of such blocks.
Allowing var would also raise the question why not also allow type and
const and this would open a can of worms. It would destroy some (much)
of the simplicity (regularity, strictness, beauty, I don't know a better
word) of the grammar.

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


Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Michael Van Canneyt



On Mon, 18 Oct 2010, Bernd Kreuss wrote:


On 18.10.2010 15:55, Frank Church wrote:


I understand the need to avoid stuff that could create unintended errors


It would create something that I would call irregularity (or even
ugliness) in the language grammar. Nowhere else is it ever allowed to
have certain things inside a begin/end block, type, const, var are all
only allowed in the *same* certain places outside of such blocks.
Allowing var would also raise the question why not also allow type and
const and this would open a can of worms. It would destroy some (much)
of the simplicity (regularity, strictness, beauty, I don't know a better
word) of the grammar.


My thoughts exactly.

Object Pascal is a simple, beautiful and easy to read language. 
The FPC team tries to keep it that way.


If someone needs convincing that this is actually a plus: 
go and (try to) read and understand any moderately complicated perl program. 
Latex2html is a nice start :-)


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


Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Benedikt Schindler

 
 I just want to create shorter variables like
 si :=  StringList.NameOfIndex(TableName.FieldByName('').AsString);
 ae := xxx;
 so:= yyy
 
 to express complicated logic with them.
 
 When I put them all at the top of the procedure, they are extra
 noise, which is not necessary for the understanding the purpose at
 the top level of the procedure.

I don't see the great extra noise of a

procedure SomeProc([someVars : Type]);
var
  [somevars : type;]
  si,ae,so : double; // temp vars for easy math;
begin
  [...]
end;

and i think the easy answer is:

No you could't, because in pascal you have to declare the vars in the
beginning of a procedure.

or:

No because this is pascal and not C

or:

why couldn't i use spanish in my english? :) *just kidding*


have all a nice day.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Sven Barth

Am 18.10.2010 16:20, schrieb Michael Van Canneyt:

Object Pascal is a simple, beautiful and easy to read language. The FPC
team tries to keep it that way.


And that is why I like the FPC team so much. :D

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


Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread David W Noon
On Mon, 18 Oct 2010 15:42:31 +0200, Florian Klaempfl wrote about Re:
[fpc-pascal] Can variables be declared within a block?:

[snip]
 It's just a matter of readability, e.g. having a variable declared in
 two blocks with the same name can cause you a lot of headache:
 
 procedure p;
 
 begin
   ...
   begin
 var i : integer;
 ...
 ...
 ...
 i:=12341234;
 ...
 ...
 ...
 ...
   end;
   ...
   ...
   ...
   begin
 var i : integer;
 ...
 writeln(i); --- this i is not the same as above so i does not
 contain 12341234 but it contains probably some garbage.
   end;

This was not usually a problem in ALGOL 60/68, PL/I or C/C++ -- these
languages have supported short scopes for up to 50 years -- as the
programmer was required to be aware of the different scopes of the
like-named variables.

I still use short scoped variables today, usually in C or C++.  I have
never had any such problems, even going back almost 40 years when I
programmed in ALGOL 60.  All block structured languages require the
programmer to understand the scope of all variables.

Indeed, short scopes can often circumvent name collisions, e.g.

 long some_func(unsigned long arg_1)
 {
long i;  /* procedure/function scoped */
unsigned max_iters;
. . .
/* calculate i, max_iters and any others */
. . .
for (unsigned i = 0; i  max_iters; ++i) /* short scope i */
{
   /* i here is distinct from the one at function scope. */
   . . .
}
. . .
return i; /* back to procedure scoped i. */
 }

Whether it is wise to use such lax naming of variables is open to
debate, but at least C and C++ allow the above.

That said, short scoping was never a part of original Pascal.  I think
Jensen  Wirth omitted it because it made the compiler simpler.
-- 
Regards,

Dave  [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
david.w.n...@ntlworld.com (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


signature.asc
Description: PGP signature
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Vannus
On 18 October 2010 15:33, Sven Barth pascaldra...@googlemail.com wrote:

 Am 18.10.2010 16:20, schrieb Michael Van Canneyt:

  Object Pascal is a simple, beautiful and easy to read language. The FPC
 team tries to keep it that way.


 And that is why I like the FPC team so much. :D


agreed.

When I went from C++ to Pascal back in 98/99, I found it quite hard
initially. Not being able to put variables anywhere  everywhere was really
awkward, but it dawned on me that I shouold be coding better.
Since then, i would say If you need vars throughout your code, then
something is wrong with your code

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

Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Reimar Grabowski
On Mon, 18 Oct 2010 19:21:57 +0100
Vannus van...@gmail.com wrote:

 Since then, i would say If you need vars throughout your code, then
 something is wrong with your code
for (int i = 0;...)
Can't see anything wrong. I use declaration of variables inside blocks quite 
often in Java and C++ but have never missed it in pascal. Please enlighten me. 
What is so bad about creating temporary variables inside blocks instead of the 
beginning of a function in a language that supports it?

R.
-- 
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] non visual timer win32

2010-10-18 Thread Justin Smyth
Guys

i have an app on win32 that runs a timer when a form is hidden , any ideas how 
i get a timer to work when the form is hidden ?

Kind Regards


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

Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Andreas Berger



for (int i = 0;...)
Can't see anything wrong. I use declaration of variables inside blocks quite 
often in Java and C++ but have never missed it in pascal. Please enlighten me. 
What is so bad about creating temporary variables inside blocks instead of the 
beginning of a function in a language that supports it?

R.
But it should make you wonder why this is no longer allowed in the 
latest C++ standards.


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


Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread David W Noon
On Mon, 18 Oct 2010 19:46:04 -0200, Andreas Berger wrote about Re:
[fpc-pascal] Can variables be declared within a block?:

 
  for (int i = 0;...)
  Can't see anything wrong. I use declaration of variables inside
  blocks quite often in Java and C++ but have never missed it in
  pascal. Please enlighten me. What is so bad about creating
  temporary variables inside blocks instead of the beginning of a
  function in a language that supports it?
 
  R.
 But it should make you wonder why this is no longer allowed in the 
 latest C++ standards.

What do you mean?

The current C++ standard (ISO 1998+TR1) permits short scope
declarations.  Indeed, C++ permits declarations to appear anywhere, not
just after a { to open a function or compound statement.  It has done
since the A.R.M. days, and in some implementations before that.
-- 
Regards,

Dave  [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
david.w.n...@ntlworld.com (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


signature.asc
Description: PGP signature
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Andreas Berger



But it should make you wonder why this is no longer allowed in the
latest C++ standards.

What do you mean?

The current C++ standard (ISO 1998+TR1) permits short scope
declarations.  Indeed, C++ permits declarations to appear anywhere, not
just after a { to open a function or compound statement.  It has done
since the A.R.M. days, and in some implementations before that.
You are correct. Been a while since I programmed in C++. The new 
standard enforces that the short scope variable declared in a for loop 
goes out of scope at the end of the loop. Older implementations did not 
always enforce this. My bad.


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


[fpc-pascal] ReadStr/WriteStr vs Val/Str

2010-10-18 Thread Richard Ward
As a user of the old Macintosh Pascal (later THINK Pascal),  both ReadStr and 
WriteStr functions were included and I used them quite a bit.   The names were 
different but the FPC implementation is basically the same as far as I can tell.

Besides backward compatibility, portability issues and personal preference, is 
there any functionality Val and Str may have that ReadStr and WriteStr don't?  
I can't see any, but wanted to make sure there there were no subtle technical 
issue(s) I might need to consider.

Thank you for implementing these functions.  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Can variables be declared within a block?

2010-10-18 Thread Dimitri Smits

- Bernd Kreuss prof7...@googlemail.com schreef:

 On 18.10.2010 15:19, Lukasz Sokol wrote:
 
  Having variables declared within code block used to require to parse
 the source code
  at least 2 times
 
 Or create them on the stack at the begin and remove them at the end
 of
 the block (which would be the only way to have some additional
 functionality through this).
 

or do the same as with that vb-ism: the 'with' keyword. Only difference(s): it 
is named/typed and it is block-scoped from the point of declaration to the end 
of the current block statement.
(I never use it, so I'm only guessing that it does something similar to the 
scenario explained above)

on the other hand, what stops the OP from using 'with'? (multiple 
levels/variables?)

and you won't die from using another stack variable scoped at the beginning of 
the method.

just to say that I'm not too fond of that c-ism in a pascal language (although 
I've used it plenty in c++, java, C#, php, ... over the years).

kind regards,
Dimitri Smits
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Re: ReadStr/WriteStr vs Val/Str

2010-10-18 Thread Paul Nicholls
Richard Ward row...@mac.com wrote in message 
news:6707d87e-2ea6-4469-97a5-cf55d1a04...@mac.com...
As a user of the old Macintosh Pascal (later THINK Pascal),  both ReadStr 
and WriteStr functions were included and I used them quite a bit.   The 
names were different but the FPC implementation is basically the same as far 
as I can tell.

Besides backward compatibility, portability issues and personal preference, 
is there any functionality Val and Str may have that ReadStr and WriteStr 
don't?  I can't see any, but wanted to make sure there there were no subtle 
technical issue(s) I might need to consider.

Thank you for implementing these functions. 
___
fpc-pascal maillist  - 
fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Hi Richard,
 I don't know about the Macintosh Pascal ReadStr and WriteStr routines 
(never used them), but a 'possible' gotcha is that I think the Str() 
function will append a space at the beginning of a value to leave room for 
the sign if negative...

if you don't want that then you can use the Format routine instead:

Integer to string:
s := Format('%d',[some integer number]);

float to string:
s := Format('%.4f',[some floating point number]); //formats a floating 
point number to 4 decimal places (just change, or remove if you want 
scientific notation I think)

I hope this helps :)

cheers,
Paul 



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


Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Jerry


On Oct 18, 2010, at 6:42 AM, Florian Klaempfl wrote:


Am 18.10.2010 14:58, schrieb Frank Church:
It's just a matter of readability, e.g. having a variable declared in
two blocks with the same name can cause you a lot of headache:


So don't allow identical names.

Ada allows exactly this feature (declaration within a block) and it is  
extremely simple and not the least confusing. It's also an easy and  
error-free way to manage dynamic memory allocation without using  
pointers.


Jerry



procedure p;

begin
 ...
 begin
   var i : integer;
   ...
   ...
   ...
   i:=12341234;
   ...
   ...
   ...
   ...
 end;
 ...
 ...
 ...
 begin
   var i : integer;
   ...
   writeln(i); --- this i is not the same as above so i does not
contain 12341234 but it contains probably some garbage.
 end;


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


Re: [fpc-pascal] Can variables be declared within a block?

2010-10-18 Thread Jürgen Hestermann

Reimar Grabowski schrieb:

for (int i = 0;...)
Can't see anything wrong. I use declaration of variables inside blocks quite often in Java and C++ 
but have never missed it in pascal. Please enlighten me. What is so bad about creating temporary variables 
inside blocks instead of the beginning of a function in a language that supports it?


I never thought about doing such declarations in Pascal.
Although I would not be against it in general (provided
that all identifiers have to be different) I see one
(small) disadvantage:

If you want to know the number of bytes pushed to the stack
(i.e. in a recursive function) then you don't have the declarations
at one place anymore but they are spread over the code which 
would make it hard to get an overview.

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