readLn or readKey method for console app

Hi,

FYI, I’m a complete newbie both in Oxygene and OS X programming. I’m writing a console app using Oxygene for OS X. There’s a function to print text to screen, writeLn. But I couldn’t find the opposite function, like readLn or something similar to that. I need to get input from keyboard. Is there a method for that? Like the old pascal’s readln or readkey function, in Oxygene library? Or should I make it myself? Any hints for that?

Thank you.

Regards,

-Bee

Unfortunately there’s nothing as simple, in the Cocoa APIs that can be cleanly used to emulate ReadLn or ReadKey… You can use scanf().

From somewhere in the internet, I found that such functionality can be done using this code. But it is written in Objective-C. Because I don’t understand Objective-C, at all. :smiley:

[NSString.alloc initWithData:
[NSFileHandle.fileHandleWithStandardInput availableData]
                          encoding:NSUTF8StringEncoding];

Can anyone help me translate it into Oxygene? Thank you.

(A) you N use “paste objective-c as Oxygene” from the edit menu to concrete this. That’s aid, if you want to do any serious Cocoa development, i would suggest to get at least a “can read” familiarity with ObjC.

(B) I doubt this will work. availableData doea not work that way. It’ll return whatever data is there, which might only be part of what the user typed. You’d have to call it repeatedly to get all the data, but then, you won’t know when to stop calling it, and it will just block and wait, if there’s no more data.

Oxygene, as a new modern pascal language variant, --I think-- has an obligation to provide these “magic” methods of pascal. All pascal language variants should (I dare to say, must) be able to compile this code:

program pascal;
var
  input: string;
begin
  write('What is your name? ');
  readln(input);
  writeln('Hello, ',input,'... welcome to Pascal!');
end.

write/ln and read/ln methods are the most basic and fundamental for input and output operation in pascal language. When I tried Oxygene for Mac using Fire, the code above couldn’t be compiled. And it requires more codes just to provide similar function as that. It surprised me at the first try. :slight_smile:

We would, but its not feasible to provide a method with the exact paradigm, on all three platforms. on .NET there’s Console.ReadlIne that does the same (and we could map to, if we wanted to provide readLn), but console input is handled vastly different on Java and Cocoa, and there’s simply no way to implement a clean and save readLn without building a whole stack on top of standard I/O that would interfere with anyone trying to use standard I/O using the platform’s standard methodologies.

Since console applications (especially those with use input) are a currencies these days, we put priority on having standard I/O work the platform standard way, over providing this method.

Sorry — i wish i had a different answer.

I understand. It’s not easy, but doable.

In this case, there are 2 standards; standard of the platform, and standard of the language. Ideally, you should fulfill and respect both standards. If not, there’s no point for having Oxygene using pascal syntax. But practically, I understand there are priority and compromise. I hope Oxygene would apply and implement both standards in the next future release. :slight_smile:

No, it’s not.

Ideally, there should be rainbows every day, and unicorns as well. and then there’s reality.

Let me repeat myself: