Recent

Author Topic: Speed of Free Pascal vs Turbo Pascal  (Read 22747 times)

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #30 on: August 16, 2015, 06:28:46 pm »
If you create a unit with a writeln() procedure and put that unit as last in the uses clause you don't have to change any lines. The writeln() from the last unit will be used. Do no need to change ask the writeln() lines. But maybe you can incorporate it in the superfastconsole unit (in those functions). Haven't looked at that yet.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #31 on: August 16, 2015, 06:37:23 pm »
If you create a unit with a writeln() procedure and put that unit as last in the uses clause you don't have to change any lines. The writeln() from the last unit will be used. Do no need to change ask the writeln() lines. But maybe you can incorporate it in the superfastconsole unit (in those functions). Haven't looked at that yet.
writeln is a compiler magic function with an open parameter count. That is not supported  by the compiler so it can't be defined.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #32 on: August 16, 2015, 11:33:51 pm »
Okay, I would suggest the following:

You can change the Write() function in SuperFastConsole as follows:
Code: [Select]
function TSuperFastConsoleStream.Write(const ABuffer; ACount: longint): longint;
var
  LNumberOfCharsToWritten: longword;
  LStdHandle: HANDLE;
  BufChar: PChar; // <--- add this variable
begin
  LNumberOfCharsToWritten := 0;
  LStdHandle := GetStdHandle(STD_OUTPUT_HANDLE);
  SetConsoleTextAttribute(LStdHandle, TextAttr);
  WriteConsole(LStdHandle, @ABuffer, ACount, LNumberOfCharsToWritten, nil);
  Result := LNumberOfCharsToWritten;

  // add the following
  BufChar := @ABuffer;
  Inc(BufChar, ACount - 1);
  if BufChar^ = #10 then
    GotoXY(WindMinX, WhereY32);

end;

When you do a Writeln() there is always a #10 printed at the end. In Write() you can check for this #10 and if so you can set the new cursor position at the new line (the linefeed is already done) at the first position of the Window (which is WindMinX).

The only problem would be if you did something like this:
Writeln('This is a test' + #13 + #10 + 'This is line 2');
(but my expectation is that you don't use #13+#10 in strings yourself.)
If you do have #13+#10 in your strings you need to split them in write() and write them individual to screen with the correct gotoxy between them.

This also doesn't scroll and wrap automatically within the given window (which crt does). If you want the scrolling and wrapping you'll need to expand the superfastconsole a whole lot more to mimic crt.
« Last Edit: August 16, 2015, 11:40:13 pm by rvk »

Elap

  • Jr. Member
  • **
  • Posts: 55
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #33 on: August 17, 2015, 11:10:39 am »
Beautiful - it's exactly what I wanted. It all works fine now. Thank you.

I haven't used anything in the Windows unit before, so this is a big learning experience for me.




Elap

  • Jr. Member
  • **
  • Posts: 55
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #34 on: August 17, 2015, 11:37:37 am »
Just to let you know that

GotoXY(WindMinX, WhereY32)

should have been

GotoXY(1, WhereY32)

because GotoXY is relative to the current window.

 

TinyPortal © 2005-2018