Coding error in Delphi 2010

I am testing Delphi 2010 and I was with the following error:
I enter this character string "096 - Construção Ltda" and I just move her / her to another variable and look at him / her, which leaves "096 - ConstruÃÃÃÃ oo Ltda", does anyone know how to find out what it is ???

Input base

001 Alkides Joao Pereira
002 Alvir Masaneiro
003 Auto Elétrica Imamura Ltda
004 Auto Peças Araújo
005 Auto Peças Porto Eixo Ltda
006 Auto Peças União
007 Azambuja Industria Comercio de Materiais de Construção Ltda

008 Balaroti Comercio De Materiais De Construção Ltda

009 Baldissera Logística e Transportes Ltda Me
010 Battistella Veículos Pesados ​​Ltda
011 Berton Diesel Auto Peças
012 Bisolo Materiais de Construção Ltda

procedure TForm1.Button2Click(Sender: TObject); var tfEntrada : TextFile; intI, intJ : Integer; strA, strS : String; procedure lerUm; //To read a registration of the file text begin inc( intI ); ReadLn( tfEntrada, strS ); strA := Copy( IntToStr( intI + 1000 ), 2, 3 ) + ' - '; Edit1.Text := strS; end; begin intI := 0; AssignFile( tfEntrada, 'nomes_tst_0001.txt' ); Reset( tfEntrada ); lerUm; while not Eof ( tfEntrada ) do begin mmEntrada.Lines.Add( strA + strS ); //I move for TMemo(mmEntrada, mmSaida), in the form mmSaida.Lines.Add( strA + strS ); lerUm; end; CloseFile( tfEntrada ); end; 

base of results

001 - Alkides Joa Pereira
002 - Alvir Masaneiro
003 - Auto Elà © trica Imamura Ltda
004 - Auto Peàs Araújo
005 - Auto Peàs Porto Eixo Ltda
006 - Auto Peças Unià £ o
007 - Azambuja Industria Comercio de Materiais de Construçà £ o Ltda
008 - Balaroti Comercio De Materiais De Construçà £ o Ltda
009 - Baldissera Logīstica e Transportes Ltda Me
010 - Battistella Veçulos Pesados ​​Ltda
011 - Berton Diesel Auto Peàs 012 - Bisolo Materiais de Construçà £ o Ltda

+4
source share
1 answer

Do not use AssignFile. This is legacy code, and it does not work with UnicodeStrings. Instead, use a TStringList or TFileStream to read the file.

[unverified]

 procedure ReadFile; var vFileReader : TstringList; begin vFileReader := TStringList.Create; try vFileReader.LoadFromFile('nomes_tst_0001.txt'); mmEntrada.Lines.Assign(vFileReader); finally vFileReader.Free; end; end; 

EDITED

Another nice solution is the following function, which I wrote a long time ago:

[test]

 function GetFileAsString(aFileName: string; aOffSet : Integer = 0; aChunkSize: Integer = -1): string; var vStream: TFileStream; vBuffer: TBytes; vCurEncoding, vDefEncoding: TEncoding; vOffSet: Integer; vFileSize: Int64; begin vCurEncoding := nil; vDefEncoding := TEncoding.Default; vStream := TFileStream.Create(aFileName, fmOpenRead + fmShareDenyNone); try if aChunkSize > 0 then begin vFileSize := aChunkSize; end else begin vFileSize := vStream.Size; end; vStream.Position := aOffSet; SetLength(vBuffer, vFileSize); vStream.ReadBuffer(Pointer(vBuffer)^, vFileSize); vOffSet := TEncoding.GetBufferEncoding(vBuffer, vCurEncoding); if (vCurEncoding <> vDefEncoding) then begin vBuffer := TEncoding.Convert(vCurEncoding, vDefEncoding, vBuffer, vOffSet, vFileSize - vOffSet); end; Result := vDefEncoding.GetString(vBuffer); finally vStream.Free; end; end; 

This function is capable of processing Unicode strings (using the specification), as well as anshing. In fact, it can read all the text files that you have.

+4
source

All Articles