Nowthat I was typing this I've noticed that Write and WriteLn don't have the same brackets in the code completion dropdown. Therefore it looks like this was not automatically generated, but it was hard-coded by someone.
Writeln is what we call a compiler "magic" function. If you look in System.pas, you won't find a Writeln that is declared anything like what you would expect. The compiler literally breaks it all down into individual calls to various special runtime library functions.
("Driver" in the context of the previous statement is just a piece of Pascal code that is hooked into the system by switching a pointer in the System unit IIRC. Been a long time since I last used this trick.)
As the prev poster said, writeln() is magic. I think the problem has to do with how the stack is assembled in a pascal function, but it's been a real long time since I've thought about where things were on the stack :)
It is magic compiler behaviour rather than regular procedure. And no, there is no way to write such subroutines (unfortunately!). Code generation resolves count of actual parameters and their types and translates to appropriate RTL calls (eg. Str()) at compile time. This opposes frequently suggested array of const (single variant array formal parameter, actually) which leads to doing the same at runtime. I'm finding later approach clumsy, it impairs code readability somewhat, and Bugland (Borland/Inprise/Codegear/Embarcadero/name it) broke Code Insight for variant open array constructors (yes, i do care, i use OutputDebugString(PChar(Format('...', [...])))) and code completion does not work properly (or at all) there. So, closest possible way to simulate magic behaviour is to declare lot of overloaded subroutines (really lot of them, one per specific formal parameter type in the specific position). One could call this a kludge too, but this is the only way to get flexibility of variable parameter list and can be hidden in the separate module.
You cannot write your own write/writeln in old Pascal. They are generated by the compiler, formatting, justification, etc. That's why some programmers like C language, even the flexible standard functions e.g. printf, scanf, can be implemented by any competent programmers.
You can even create an identical printf function for C if you are inclined to create something more performant than the one implemented by the C vendor. There's no magic trickery in them, your code just need to "walk" the variable arguments.
Writeln is not "array of const" based, but decomposed by the compiler into various calls that convert the arguments to string and then call the primitive writestring. The "LN" is just a function that writes the lineending as a string. (OS dependant). The procedure variables (function pointers) for the primitives are part of the file type (Textrec/filerec), which is why they can be customized. (e.g. AssignCrt in TP)
will be converted to be ABI compatible to C, printf style. This means that the relevant function (somehting in this case) can't get the number of arguments, but must rely on formatstring parsing. So this is something different from array of const, which is safe.
Although not a direct answer to you question, I would like to add the following comment:I have recently rewritten some code using Writeln(...) syntax into using a StringList, filling the 'lines' with Format(...) and just plain IntToStr(...), FloatToStr(...) functions and the like.
Hi,
how can I write text to the black error output section at the bottom of the Arduino IDE? is it possible?
I just want to be able to view the state of my variables etc.
I read about Serial.print etc but it doesn't explain much about where you can see the text.
Fixed my mistake, sorry I wrote the wrong method name - Serial.writeln() vs Serial.println() is a small error in the grand scheme of what I was trying to do, which was give an actual answer where only snark had existed before.
In the Arduino environment, choose: "Tools -> Serial Monitor" from the menu and a console window will open and your output should display there. It did not output to the black status area at the bottom of the sketch window.
frenzal_dude:
Hi,
how can I write text to the black error output section at the bottom of the Arduino IDE? is it possible?
I just want to be able to view the state of my variables etc.
I read about Serial.print etc but it doesn't explain much about where you can see the text.
Seeing as this is the very first Google result that appears when searching out how to write debug messages to the console, the last post previous to the one I quoted was perfect. It explained what code to write, and how to see it in the IDE. Thank you tanzz, BulldogLowell and stutteringp0et for helpful responses to get me going.
Unfortunately, it's a wonder I made it to the good stuff, because the first responses (from PaulS) were very off-putting and disheartening to read. Thought this all was supposed to be fun, but then there's some a*& giving a novice a hard time. I'm an experienced programmer in C#, C++, etc but new to the Arduino. I hope the community is a lot nicer in general than PaulS!
I'm quite sure you have not become a professional developer without becoming a regular "looker-up" of technical details - whether in the official documentation or elsewhere. And I'm also quite sure that you would find it irritating for people to ask you routine questions about your products to which they could easily have got the answer by reading the documentation you wrote.
Line 12 : document.writeln(exp1 , exp2) passes two parameters to the function to write in the HTML document. This prints both parameters in the same line and adds a new line after it.
Document.writeln( ) behaves just likeDocument.write( ) except that after appending allof its arguments to document, it alsoappends a newline character. See the Document.write( )reference page for more information on this method.
Back in the days when I was programming in Pascal, I'd often use writeln to
display debug information - basically just to know what the program was
doing at that moment.Recently I've started developing in Delphi, but when I tried to add a
writeln statement, I got an error (I/O error 105 IIRC). Is there a way to output debug information to some sort of console? Perhaps
to the messages list in Turbo Delphi?Coming from a Java background, I was used to using Log4J for larger
projects. I've already found a Log4Delphi project, but I'd like to steer
clear of that for a while, since my applications are extremely simple at
the moment.All thoughts or suggestions are highly appreciated!Ikke
Afaik "GUI" Windows programs are simply programs that don't open a console.So either use window opening calls from a console application (IOW setup for
event driven running), or try to initialise a console from a previously GUI
program.I'm not 100% sure, but afaik both are possible.
VB uses "debug.print" as an equivalent, which prints to the immediate
window when running in the IDE. Maybe Delphi has an equivalent?
--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
True. But some languages, when you start your Windows Application from a
console, still show the console output in said console.If you start your application by double-clicking on it's icon, the
console output remains hidden.
I'm really only looking for something like 'writeln' - anything that's
more complex than that, should be discarded as a viable solution.If there is none, the simplest solution could be logging to a file and
simply tailing it's contents. That way, I can still see what the software
is doing in realtime.Thanks,Ikke
Finally! A topic on which I can say something useful!I use the OutputDebugString function to write out debugging info. When running the program under the Delphi IDE, the lines show up in the Events window. For when I'm running it outside of the IDE, I use the DbgView program from
sysinternals.com to capture and display them.
--
Dale
I wish I knew about that function a while ago. I added a separate Debug
form with a Memo, and at critical points in the program I wrote a line of
information which told me what procedure I was entering or exiting, as well
as a time stamp with 0.1 second accuracy. That was helpful in debugging my
serial interface application, which had to send strings or characters to
the serial port, wait for some time, and then read back from the input
buffer. I was able to see where sometimes my timeout loops went for quite a
few iterations, while at other times the expected event happened just about
immediately.My debug window remains hidden, but I have a menu item to view it. When the
program closes, it is written to an .dbg text file.Paul
> Finally! A topic on which I can say something useful!
>
> I use the OutputDebugString function to write out debugging info. When
> running the program under the Delphi IDE, the lines show up in the
> Events window. For when I'm running it outside of the IDE, I use the
You can write to the console with Writeln, but only once your program
has a console. Call AllocConsole for that.You can write to Delphi's debug log with OutputDebugString.You can write to a log file with whatever library tool you wish.You can display a message with ShowMessage.--
Rob
AllocConsole will give you a console window, it will have your title
on it etc...
You can use the Writeln and other things related to console windows
that are default as pascal IO.. BUt use FreeConsole somewhere before your app terminates.
--
"I'm never wrong, once i thought i was, but was mistaken"
Real Programmers Do things like this.
_5
But there are countable bugs there *are* fixed. So how can you say that
the bug will never get fixed?QC is for more than reporting bugs to CodeGear. It's also for
documenting bugs. Post a bug to QC, and now people can find that bug to
confirm that whatever they're observing is the same as whatever you
already observed. Collective memory. Maybe you've found a workaround.
Post it to QC so others can benefit from your solution.--
Rob
3a8082e126