Re: [fpc-pascal] const parameter writeable

2006-05-02 Thread Michael Müller
On Mon, May 01, 2006 at 12:07:55PM -0600, L505 [EMAIL PROTECTED] wrote:
 
   Only the pointer itself is the parameter and read-only. Where the pointer
   points to is irrelevant.
 
 I remember this from using classes where you can still access the class 
 properties -
 should have thought about that before posing the question :).
 
 
  But in this case I'm wondering why you want to give a pointer instead
  of the real type?
 
 
 did you mean this ? :
 
procedure ChangeRec1(const Rec: TSomeRec);
begin
  Rec.a:= 'string A';
end;

Yes.

 Because I can't pass a PSomeRec to that function, only a TSomeRec

Where is the problem? If you allocated the memory by new() as in your
example you could call
ChangeRec1(RecPtr^);
and the compile (hopefully) uses the pointer.

But in this case you will get an compiler error because you can't
change a constant value.

It seemed that I didn't get the point from your original mail:
Name the procedure CHANGERec1 and change a value but declare the
parameter as constant.

 Otherwise, I don't know what you mean..

Now _I_'m a little bit confused.

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


[fpc-pascal] Constant object

2006-05-02 Thread Michael Müller
How can I declare a constant object?

var
  MyTest: TObject;
begin
  MyTest := TObject.Create;
end.

works (for sure).

How can I declare 'const'?

Thanks

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


Re: [fpc-pascal] const parameter writeable

2006-05-02 Thread L505
  
   But in this case I'm wondering why you want to give a pointer instead
   of the real type?
 
 
  did you mean this ? :
 
 procedure ChangeRec1(const Rec: TSomeRec);
 begin
   Rec.a:= 'string A';
 end;

 Yes.

Well, this is a Precord. That doesn't work. That is why I was confused.


  Because I can't pass a PSomeRec to that function, only a TSomeRec

 Where is the problem? If you allocated the memory by new() as in your
 example you could call
 ChangeRec1(RecPtr^);
 and the compile (hopefully) uses the pointer.

Yes, but you are repeating what Jonas says - if you would have told me this 
first, you
would have gotten the brownie points. But Jonas gets them. :-)


 But in this case you will get an compiler error because you can't
 change a constant value.

 It seemed that I didn't get the point from your original mail:
 Name the procedure CHANGERec1 and change a value but declare the
 parameter as constant.

I was asking why I could write to a const. But in fact I was not writing to the 
CONST, I
was actually writing to the const data it pointed to.  With SomeRec^ I cannot 
write to
const. Problem solved.

I was using sloppy Delphi style code without ^ since Delphi enforces this 
sloppy style of
coding, and now I know why not to use sloppy delphi style code. 

What I was confused about was why you recommended TSomeRec when we are dealing 
with
PSomeRec.

I also stated that I knew you can pass TSomeClass as a const, you can still 
access it's
properties even though it is a const.

 program project1;

 {$mode objfpc}{$H+}

   type
 TSomeClass = class
   a: string;
   b: string;
 end;

   procedure ChangeClass(const SomeClass: TSomeClass);
   begin
 SomeClass.a:= 'string A';
   end;

 var
   SomeClass: TSomeClass;
 begin
   someclass:= TSomeClass.create;
   ChangeClass(someclass);
   writeln(someclass.a);
   someclass.free;
   readln;
 end.

This is normal, because we are passing a pointer when dealing with a class - 
not passing
the class contents. Which is really what I should have thought about before 
asking the
question, because I have discovered you can write to a const class *contents* 
before. 

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


[fpc-pascal] sort procedure of T(FP)List

2006-05-02 Thread Marc Santhoff
Hi,

i wonder why the declaration of the comparing function of list objects
is the way it is:

TListSortCompare = function (Item1, Item2: Pointer): Integer;

Since I am writing a class that sorts a list it owns depending on
another property naming the property of the list items for sorting, I
would like to have it made a procedure of object:

TListSortCompare = function (Item1, Item2: Pointer): Integer of object;

I'm dealing with lists of files and directories that should get sorted
by name, date, ...
If the comparing function is a plain non object function I have to make
some sort of unit global variable or the like for telling it, what
property is the sort criteria. I don't like this design, although in
this case there is only one soritng process at a time.

Is this a concession imposed by Delphi compatibility?

(If you can suggest a better strategy for using this stuff, please do.)

TIA;
Marc


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


Re: [fpc-pascal] eof strangeness

2006-05-02 Thread Bob Richards
John Coppens wrote:

 program testeof;
 
 begin
   if eof then
 writeln('EOF found')
   else
 writeln('No EOF found');
 end.
 
 This sample program doesn't return till enter is pressed.

That's correct and reasonable. You are terminating your program after an EOL 
(ENTER), If
you send it an EOF ^d it also responds reasonably.

$ ./testeof
   ^d entered at kybd
EOF found

Bob

-- 
PGP Encrypted E-Mail Prefered
Public Key at: http://www.tamara-b.org/~bob/pubkey.asc
.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] string comparison on various platforms

2006-05-02 Thread Marc Santhoff
Hi,

from digging the sources I know, that on Unix-like Systems the
comparison of strings is done according to the current locale (Pascals
strcomp is mapped to C-libs strcoll).

Can I assume that this is done similar on all other platforms, too?

I'm asking myself if I have to consider something special when sorting
strings or if a comparison using the RTL function will allways be
correct (not talking of special sort orders for rarely occuring
cases).

TIA,
Marc


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


Re: [fpc-pascal] aterm won't run fp

2006-05-02 Thread John Coppens
On Tue, 25 Apr 2006 08:52:05 +0200 (CEST)
[EMAIL PROTECTED] (Marco van de Voort) wrote:

  Can anyone tell me what's missing to get aterm to run fp?
 
 Implementation of the Xterm terminal standard ? :)
 
 Debugging startup (possibly using a simpler example like installer
 first), is the only real solution I think.

Just in case someone bumps into the same problem - Thanks to some
suggestions on the IRC channel, I solved the aterm problem with:

aterm -tn xterm -e fp

Surprisingly 'aterm -tn rxvt -e fp' does not work (but rxvt -e fp does
work!)

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