Discussion:
sample stack programm
(too old to reply)
schrei
2007-07-25 20:16:58 UTC
Permalink
Hallo!

I?m trying to translate a borland pascal sample program to gpcp.
The lines "Sys.Console.WriteLine(myEnumerator.Current);" and
"Sys.Console.WriteLine(myStack.Count);" does not compile. Why does it
not compile?
The delphi sample programm is here
http://delphi.about.com/library/fcl/system/collections/blfclstack.htm

Kind regards
Helmut

MODULE SamplesStack;
IMPORT Col := mscorlib_System_Collections, Sys := mscorlib_System, CPmain;

VAR myStack : Col.Stack;

PROCEDURE PrintValues(myCollection: Col.IEnumerable);
VAR myEnumerator: Col.IEnumerator;
BEGIN
myEnumerator := myCollection.GetEnumerator;
WHILE myEnumerator.MoveNext DO
Sys.Console.WriteLine(myEnumerator.Current);
END;
Sys.Console.WriteLine;
END PrintValues;

BEGIN
NEW(myStack );
myStack .Push("Hallo");
Sys.Console.WriteLine(myStack);
Sys.Console.WriteLine(myStack.Count);
PrintValues(myStack);
END SamplesStack.
Pascal Bourguignon
2007-07-25 20:27:49 UTC
Permalink
Post by schrei
I?m trying to translate a borland pascal sample program to gpcp.
The lines "Sys.Console.WriteLine(myEnumerator.Current);" and
"Sys.Console.WriteLine(myStack.Count);" does not compile. Why does it
not compile?
You're asking the wrong channel. You should be asking your compiler
itself. It tells you why it doesn't compile, in the guise of an
"error message".
--
__Pascal Bourguignon__ http://www.informatimago.com/

The world will now reboot. don't bother saving your artefacts.
Chris Burrows
2007-07-26 00:32:15 UTC
Permalink
Post by schrei
Hallo!
I?m trying to translate a borland pascal sample program to gpcp.
The lines "Sys.Console.WriteLine(myEnumerator.Current);" and
"Sys.Console.WriteLine(myStack.Count);" does not compile. Why does it not
compile?
The delphi sample programm is here
http://delphi.about.com/library/fcl/system/collections/blfclstack.htm
Kind regards
Helmut
Hi Helmut,

There are two separate issues here:

1. The Component Pascal language does not have 'properties'. Thus you have
to use the 'getter' and 'setter' versions of the API calls when accessing
.NET properties.

in Delphi: myEnumerator.Current
in GPCP: myEnumerator.get_Current()

2. When referencing a parameterless procedure in Component Pascal you should
still include the parentheses:

in Delphi: myEnumerator.MoveNext
in GPCP: myEnumerator.MoveNext()

A working version of your program is:

MODULE SamplesStack;

IMPORT
Col := mscorlib_System_Collections,
Sys := mscorlib_System,
CPmain;

VAR myStack: Col.Stack;

PROCEDURE PrintValues(myCollection: Col.IEnumerable);
VAR myEnumerator: Col.IEnumerator;
BEGIN
myEnumerator := myCollection.GetEnumerator();
WHILE myEnumerator.MoveNext() DO
Sys.Console.WriteLine(myEnumerator.get_Current())
END;
Sys.Console.WriteLine
END PrintValues;

BEGIN
NEW(myStack);
myStack.Push("Hallo");
Sys.Console.WriteLine(myStack);
Sys.Console.WriteLine(myStack.get_Count());
PrintValues(myStack)
END SamplesStack.

There are twenty or so GPCP for .NET source code examples on my website that
you should find useful:

http://www.cfbsoftware.com/gpcp/examples.htm

Regards,
Chris Burrows
CFB Software
http://www.cfbsoftware.com/cpide

Loading...