Recent

Author Topic: Ansistring and Pipline in German Windows  (Read 1317 times)

alfware17

  • New Member
  • *
  • Posts: 29
Ansistring and Pipline in German Windows
« on: December 26, 2018, 06:38:15 pm »
Hallo und Merry Christmas,

I have a special problem / not funny effect after porting an elder Free Pascal program from Pascal Strings to Ansistring.
The program worked fine for 10 years or so, until I decided to use Ansistring ({$H+}). I did it only for reason of longer than 255 characters
but most users will never need. Its a program reading file or standard input (pipeline by < ), processes and writes back to file or standard
output (pipeline by > ).
The effect is only with Ansistrings it will not read and/or write correct data. Its a OEM/Ansi thing I guess and I have applicable filters,
but I dont understand the logic. If I use files for input/output then all is fine. If I call both pipelines ( < and > ) also all seems to be fine.
But if I mix (file and pipeline) then it goes wrong. With pascal strings it worked! The program fails also if both pipes are used but for any
reason temporary data is written to file.
I could find out, when my program uses mix file / pipeline and then when I need the filter and in wich direction. I could leave the thing
and go back to pascal string. But maybe anybody can explain me, whats there going on. Are there special READLN/WRITELN needed for
Ansistring and/or for standard input/output? Do I need a codepage? I wouldnt like to destroy the structure of the program with more
special cases - it already differs from 16/32/64 bit but worked fine until the Ansistrings. >:D

Greetings Bernd

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Ansistring and Pipline in German Windows
« Reply #1 on: December 26, 2018, 09:22:54 pm »
Do you get the same problem if you start your app with:
Code: Pascal  [Select][+][-]
  1.   DefaultSystemCodePage := TextRec(Output).CodePage;

alfware17

  • New Member
  • *
  • Posts: 29
Re: Ansistring and Pipline in German Windows
« Reply #2 on: December 26, 2018, 11:13:25 pm »
Do you get the same problem if you start your app with:


Sorry but this is a batch program - called from script and/or command line.

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Ansistring and Pipline in German Windows
« Reply #3 on: December 27, 2018, 03:08:42 am »
Are you using Google Translate to read my answer? It gave you wrong translation. What I wrote above is a code you need to add inside your program.

By the way, what do you get for the following code:
Code: Pascal  [Select][+][-]
  1.   WriteLn('DefaultSystemCodePage: ', DefaultSystemCodePage);
  2.   WriteLn('TextRec(Output).CodePage: ', TextRec(Output).CodePage);
  3.   WriteLn('TextRec(Input).CodePage: ', TextRec(Input).CodePage);

Like in:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes
  10.   { you can add units after this };
  11.  
  12. begin
  13.   //DefaultSystemCodePage := TextRec(Output).CodePage;  <--- try this line in your code. Uncommented!!
  14.   WriteLn('DefaultSystemCodePage: ',DefaultSystemCodePage);
  15.   WriteLn('TextRec(Output).CodePage: ',TextRec(Output).CodePage);
  16.   WriteLn('TextRec(Input).CodePage: ',TextRec(Input).CodePage);
  17.   ReadLn;
  18. end.
« Last Edit: December 27, 2018, 04:04:37 am by engkin »

alfware17

  • New Member
  • *
  • Posts: 29
Re: Ansistring and Pipline in German Windows
« Reply #4 on: December 27, 2018, 05:51:55 pm »
Hey engkin,

your code changed the codepage from 1252 to 850.
Dont know if this is standard for German Windows 7,
but my test-program now works with the ansi-string as well as it did with the pascal string.
I made complete test (OEM, ANSI, CP850, data, code, pipeline, files, mixed and temporary)
to be sure, it does. (look my attachment and special the MD5).
The test-programs are similar like

Code: Pascal  [Select][+][-]
  1. {$h+}
  2. program test_ansi_pipe_temp_pipe;
  3. var zeile: string;
  4.     datei: text;
  5. begin
  6.    DefaultSystemCodePage := TextRec(Output).CodePage;
  7.    assign(datei,'temp.txt'); rewrite(datei);
  8.    readln(zeile);
  9.    while not eof do begin
  10.       writeln(datei,zeile);
  11.       readln(zeile);
  12.    end;
  13.    writeln(datei,zeile);
  14.    close(datei); reset(datei);
  15.    readln(datei,zeile);
  16.    while not eof(datei) do begin
  17.       writeln(zeile);
  18.       readln(datei,zeile);
  19.    end;
  20.    writeln(zeile);
  21.    close(datei);
  22. end.

Clones, with files or input/output with temp or without, anyway.

Now I just hope the original application will do the same with your line of code
(is more complex and under construction for other reason than the ansistring).

Thanks so far ::)

 

TinyPortal © 2005-2018