Recent

Author Topic: What is buffer and how to use it?  (Read 4980 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8522
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: What is buffer and how to use it?
« Reply #15 on: November 19, 2022, 01:53:03 pm »
thank you Leledumbo. It works. You are using some syntax FPC compiler doesn't accept though. Like SysUtils need to be declared, can't call SysUtils.Sleep() directly. And then  since it is declared, I can just call Sleep().
What version are you using? I only test on latest stable and latest trunk, nothing prior to them. And surely both work as expected.
I remember C# is like that, no need to declare if you don't mind typing the whole thing every time. FPC apparently not. Maybe in Delphi it is possible?
It's just for clarity, FPC and Delphi are the same in this regard, no need to qualify if you're sure which one to call of you want to override through the uses clause order.
A bit of mind-bending though, how it works. In your example, in my mind, as soon as you handle it to function PrintChar(), user is stuck in infinite loop. But, keyboard input is still handled, in parallel?
Yep, more or less is like that.

Bogen85

  • Sr. Member
  • ****
  • Posts: 367
Re: What is buffer and how to use it?
« Reply #16 on: November 19, 2022, 04:35:03 pm »
What version are you using? I only test on latest stable and latest trunk, nothing prior to them. And surely both work as expected.

Which is what I did to confirm.

I just tried Leledumbo's program with FPC 3.3.1 and 3.2.2. Both compiled it and the resulting executables ran as expected.

However, there was an illegal character I had to remove close to the top.


The 0xC2 at offset 0x14.


Code: Text  [Select][+][-]
  1. $ hexdump -C 42592.pas | head -n 3
  2. 00000000  7b 24 6d 6f 64 65 20 6f  62 6a 66 70 63 7d 7b 24  |{$mode objfpc}{$|
  3. 00000010  48 2b 7d 0a c2 a0 0a 75  73 65 73 0a 20 20 7b 24  |H+}....uses.  {$|
  4. 00000020  69 66 64 65 66 20 75 6e  69 78 7d 0a 20 20 63 74  |ifdef unix}.  ct|
  5.  

Code: Text  [Select][+][-]
  1. $ fpc 42592.pas
  2. Free Pascal Compiler version 3.2.2 [2022/08/17] for x86_64
  3. Copyright (c) 1993-2021 by Florian Klaempfl and others
  4. Target OS: Linux for x86-64
  5. Compiling 42592.pas
  6. 42592.pas(2,1) Fatal: illegal character "'�'" ($C2)
  7. 42592.pas(2,1) Fatal: Compilation aborted
  8. Error: /usr/bin/ppcx64 returned an error exitcode
  9.  

Code: Text  [Select][+][-]
  1. $ fpc 42592.pas
  2. Free Pascal Compiler version 3.3.1 [2022/11/18] for x86_64
  3. Copyright (c) 1993-2022 by Florian Klaempfl and others
  4. Target OS: Linux for x86-64
  5. Compiling 42592.pas
  6. 42592.pas(2,1) Fatal: Illegal character "'�'" ($C2)
  7. Fatal: Compilation aborted
  8. Error: /home/dev/fpc_usr/lib/fpc/3.3.1/ppcx64 returned an error exitcode
  9.  

Bogen85

  • Sr. Member
  • ****
  • Posts: 367
Re: What is buffer and how to use it?
« Reply #17 on: November 19, 2022, 05:19:29 pm »
@Leledumbo this is the first time I've had in this happen in copying pasting code from the Forums here.

However, there was an illegal character I had to remove close to the top.
The 0xC2 at offset 0x14.

https://www.codetable.net/hex/c2

Not sure if this was an extra character from your side, or something in the forum software.

It is strange though, it is only when I copy/paste your code example. I can't find it in the HTML source either as the illegal character or the above HTML entity.

And it is not always showing up in the same location, if I use the [Select] from the forum I get this:
Code: Text  [Select][+][-]
  1. 00000000  20 20 20 20 7b 24 6d 6f  64 65 20 6f 62 6a 66 70  |    {$mode objfp|
  2. 00000010  63 7d 7b 24 48 2b 7d 0a  20 20 20 20 c2 a0 0a 20  |c}{$H+}.    ... |
  3. 00000020  20 20 20 75 73 65 73 0a  20 20 20 20 20 20 7b 24  |   uses.      {$|
  4.  

Whereas If I just copy the code:
Code: Text  [Select][+][-]
  1. 00000000  7b 24 6d 6f 64 65 20 6f  62 6a 66 70 63 7d 7b 24  |{$mode objfpc}{$|
  2. 00000010  48 2b 7d 0a c2 a0 0a 75  73 65 73 0a 20 20 7b 24  |H+}....uses.  {$|
  3. 00000020  69 66 64 65 66 20 75 6e  69 78 7d 0a 20 20 63 74  |ifdef unix}.  ct|
  4.  

But I digress....
I only tried to compile/run it in the first place because @Weiss said FPC would not accept it...






Weiss

  • New Member
  • *
  • Posts: 46
Re: What is buffer and how to use it?
« Reply #18 on: November 20, 2022, 02:15:24 am »
What version are you using?

3.2.2.

I went over your example again and noticed that you DO have SysUtils in uses clause. 

I can't copy-paste, have to read from screen and re-type on my other little laptop. Must have missed it while typing.

Or probably, omitted SysUtils as soon as I saw the syntax SysUtils.Sleep(), kind of presumed it is possible in FPC. But it is not.

So, the call SysUtils.Sleep() is not possible without including SysUtils in uses. I checked other calls, too. Mouse.GetMouseY does not compile without including mouse in uses. I definitely misunderstood what you were talking about, please expand on what you meant here:

It's just for clarity, FPC and Delphi are the same in this regard, no need to qualify if you're sure which one to call of you want to override through the uses clause order.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8522
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: What is buffer and how to use it?
« Reply #19 on: November 20, 2022, 10:13:24 pm »
So, the call SysUtils.Sleep() is not possible without including SysUtils in uses. I checked other calls, too. Mouse.GetMouseY does not compile without including mouse in uses. I definitely misunderstood what you were talking about, please expand on what you meant here:
<unit name>.<identifier> is a way to explicitly say where the compiler should look the identifier for, regardless of uses clause order. So if you have:
Code: Pascal  [Select][+][-]
  1. uses
  2.   SysUtils,Windows;
  3. ...
  4. Sleep();
  5.  
It will refer to Windows.Sleep() as Windows is placed after SysUtils. But if you have:
Code: Pascal  [Select][+][-]
  1. uses
  2.   Windows, SysUtils;
  3. ...
  4. Sleep();
  5.  
It will be SysUtils.Sleep() to call. So if you want to be sure that an identifier you call is from a specific unit, regardless of the order in the uses clause, you qualify it with the unit name.
Code: Pascal  [Select][+][-]
  1. uses
  2.   SysUtils,Windows;
  3. ...
  4. SysUtils.Sleep();
  5.  
will always call SysUtils.Sleep(), even if Windows unit also has Sleep() identifier. OTOH, you might want the totally opposite case. You want to control which identifier to call solely from the uses clause. This is a common practice in Pascal, one notable example is from fcl-web. You can have this:
Code: Pascal  [Select][+][-]
  1. uses
  2.   fphttpapp;
  3. ...
  4. begin
  5.   Application.Initialize;
  6.   Application.Run;
  7. end.
  8.  
Just by changing the fphttpapp to fpCGI or fpFCGI, you web app magically switches to CGI or FastCGI, respectively, from embedded server.

Weiss

  • New Member
  • *
  • Posts: 46
Re: What is buffer and how to use it?
« Reply #20 on: November 21, 2022, 12:39:23 am »
appreciated! Thank you Leledumbo.

 

TinyPortal © 2005-2018