Recent

Author Topic: Why lazarus convert the encoding of files in mode graphical?  (Read 5227 times)

dicas3d

  • Jr. Member
  • **
  • Posts: 81
    • Site oficial do Lazarus Portugal
I use Lazarus 0.9.28.2 and I have a problem. I write a file with my program writed in Lazarus. This file is of type RECORD. And when i try read the file in the same program it don't read appropriately. It shows squares but not the correct data.
In the write moment i have this code:
Code: Pascal  [Select][+][-]
  1. dir := c + '\carros.sgs';
  2. delete(dir,0,4);
  3. carrosarray[i+1].nome := InputBox('Criar carro','Introduza o nome do carro','');
  4. system.Assign(carrosfile, dir);
  5. system.ReWrite(carrosfile);
  6. For contador := 1 to i + 1 do begin
  7.      Write(carrosfile, carrosarray[contador]);
  8. End;
  9. system.Close(carrosfile);
At the read moment i have this code:
Code: Pascal  [Select][+][-]
  1.  dir := c + '\carros.sgs';
  2.  system.assign(carrosfile,dir);
  3.  system.ReSet(carrosfile);
  4.  i := 1;
  5.  contador := 1;
  6.  while not eof(carrosfile) do begin
  7.        system.Seek(carrosfile, contador-1);
  8.        Read(carrosfile, carrosarray[contador]);
  9.        i := i + 1;
  10.        contador:=contador+1;
  11.  end;
  12.  system.Close(carrosfile);
« Last Edit: July 02, 2010, 07:00:51 pm by dicas3d »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Why lazarus convert the encoding of files in mode graphical?
« Reply #1 on: July 02, 2010, 07:10:24 pm »
Try this:
Code: [Select]
Write(carrosfile, carrosarray[contador][1]);

dicas3d

  • Jr. Member
  • **
  • Posts: 81
    • Site oficial do Lazarus Portugal
Re: Why lazarus convert the encoding of files in mode graphical?
« Reply #2 on: July 05, 2010, 10:00:21 am »
Don't work.

dicas3d

  • Jr. Member
  • **
  • Posts: 81
    • Site oficial do Lazarus Portugal
Re: Why lazarus convert the encoding of files in mode graphical?
« Reply #3 on: July 05, 2010, 12:40:13 pm »
I can solute it. The trick is remove the "{$H+}" from the top of the unit that have the RECORD's. To avoid problems the RECORD's must has be on a separated unit.

vvzh

  • Jr. Member
  • **
  • Posts: 58
Re: Why lazarus convert the encoding of files in mode graphical?
« Reply #4 on: July 05, 2010, 02:51:27 pm »
You can try to use "string[255]" instead of plain "string" in record fields and keep {$H+} directive. This way there is no need in separate unit.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2680
Re: Why lazarus convert the encoding of files in mode graphical?
« Reply #5 on: July 07, 2010, 11:11:44 am »
Better not to fiddle with directives if you need shortstrings in a record.
as vvzh said you can use sting[nn] for a fixed length string or just ShortString (which is a string[255])
Same if you need ansistrings, just use AnsiString instead of string.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

 

TinyPortal © 2005-2018