Recent

Author Topic: TMemoryStreamUTF8 cannot LoadFromFile  (Read 2110 times)

BeniBela

  • Hero Member
  • *****
  • Posts: 842
    • homepage
Re: TMemoryStreamUTF8 cannot LoadFromFile
« Reply #30 on: June 24, 2022, 11:29:16 am »
TmemorystreamUTF8 is a nonsense. A stream is a stream and always byte sized.
I would have fired the author. Simply because of proven lack of knowledge.

All the streams are nonsense.

In Pascal, you read files with AssignFile/Reset/Read. You do not need classes for that

PascalDragon

  • Hero Member
  • *****
  • Posts: 4311
  • Compiler Developer
Re: TMemoryStreamUTF8 cannot LoadFromFile
« Reply #31 on: June 24, 2022, 01:00:28 pm »
In Pascal, you read files with AssignFile/Reset/Read. You do not need classes for that

In Object Pascal - especially when compatible with LCL/VCL -  file handling is done with TFileStream and friends, not with Pascal I/O.

martinrame

  • Full Member
  • ***
  • Posts: 114
Re: TMemoryStreamUTF8 cannot LoadFromFile
« Reply #32 on: June 24, 2022, 01:56:30 pm »
Well, as this is taking too long I finally somewhat solved this way:

1. The CGI program gets the Id file (from the database, there's a relation between the filename and an Id).
2. The CGI runs (using TProcess) an external executable passing the ID as param.
3. The executable receives the ID, do an SQL query to find the filename, loads it into a TMemoryStream, saves to a new file called /tmp/<ID>.pdf and writes 'ok' to stdout.
4. The CGI reads the result of the program, if it's 'ok' then reads the file into a TMemoryStream and sends its content to the client.

Awful, but works.
« Last Edit: June 24, 2022, 02:04:41 pm by martinrame »

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1050
Re: TMemoryStreamUTF8 cannot LoadFromFile
« Reply #33 on: June 24, 2022, 02:30:17 pm »
Did you try to convert the name from the console code page?

martinrame

  • Full Member
  • ***
  • Posts: 114
Re: TMemoryStreamUTF8 cannot LoadFromFile
« Reply #34 on: June 24, 2022, 02:56:42 pm »
I tried everything, it looks like an issue related to Apache and/or the CGI, because the same program from command line works without issues.

Thaddy

  • Hero Member
  • *****
  • Posts: 11774
Re: TMemoryStreamUTF8 cannot LoadFromFile
« Reply #35 on: June 24, 2022, 04:25:13 pm »
The file name, not the content...... < sigh> and even that is nonsense. That class has no right to live....
Black themes should be banned.

dsiders

  • Hero Member
  • *****
  • Posts: 673
Re: TMemoryStreamUTF8 cannot LoadFromFile
« Reply #36 on: June 24, 2022, 07:15:48 pm »
The file name, not the content...... < sigh> and even that is nonsense. That class has no right to live....

Well, it has been marked as deprecated, so...
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

Thaddy

  • Hero Member
  • *****
  • Posts: 11774
Re: TMemoryStreamUTF8 cannot LoadFromFile
« Reply #37 on: June 24, 2022, 09:28:04 pm »
....it should be removed...
Black themes should be banned.

PascalDragon

  • Hero Member
  • *****
  • Posts: 4311
  • Compiler Developer
Re: TMemoryStreamUTF8 cannot LoadFromFile
« Reply #38 on: June 25, 2022, 06:31:42 pm »
I tried everything, it looks like an issue related to Apache and/or the CGI, because the same program from command line works without issues.

So to clear that up: if you run the program without any involvment of Apache you can correctly open the file with the non-ASCII characters? And if you do it inside Apache you can't?

martinrame

  • Full Member
  • ***
  • Posts: 114
Re: TMemoryStreamUTF8 cannot LoadFromFile
« Reply #39 on: June 27, 2022, 01:50:03 pm »
I tried everything, it looks like an issue related to Apache and/or the CGI, because the same program from command line works without issues.

So to clear that up: if you run the program without any involvment of Apache you can correctly open the file with the non-ASCII characters? And if you do it inside Apache you can't?

Exactly.

PascalDragon

  • Hero Member
  • *****
  • Posts: 4311
  • Compiler Developer
Re: TMemoryStreamUTF8 cannot LoadFromFile
« Reply #40 on: June 28, 2022, 01:28:12 pm »
Would you please dump the environment variables for both cases? Maybe there is some difference that can point to the issue.

 

TinyPortal © 2005-2018