델파이에서 유니코드로 텍스트파일 어떻게 쓰나요??

델파이에서 쿼리로 가져온 값들을

유니코드로 텍스트 파일을 쓰고 싶습니다

몇번 시도하다가 안되서 이렇게 질문남기네요

도와주세요!

    1개의 답변이 있어요!

    • 안녕하세요??

      한마디로 쿼리 결과값들을 유니코드로 텍스트파일에 저장하고싶다고 하셨는데

      예제로 통해서 보여드리겠습니다

      밑에 예제는 저장할 텍스트 파일을 지정하고 유니코드 파일로 포맷을 바꾼다음

      zquery라는 컴포넌트를 이용해서 가져온 결과값을 저장했습니다

      참고하시기 바랍니다^^

      if SD.Execute then begin if FileExists(SD.FileName) then begin DeleteFile(SD.FileName); end; FileStream := TFileStream.Create(SD.FileName, fmCreate); try try ByteOrderMarker := $FEFF; // 유니코드라는 뜻. 모든 유니코드 파일은 $FEFF 로 시작함. FileStream.WriteBuffer(ByteOrderMarker, SizeOf(ByteOrderMarker)); WS := WideString('필드1' + #9 + '필드2' + #9 + '필드3' + #13#10); //field caption FileStream.WriteBuffer(ws[1], Length(ws) * SizeOf(ws[1])); while not ZQuery.Eof do begin WS := WideString(ZQuery.FieldByName('field1').AsString + #9 + ZQuery.FieldByName('field2').AsString + #9 + ZQuery.FieldByName('field3').AsString + #13#10); FileStream.WriteBuffer(ws[1], Length(ws) * SizeOf(ws[1])); ZQuery.Next; end; except on E: Exception do Application.MessageBox('예기치 못한 상황이 발생하였습니다.' + #13#10 + '프로그램을 재부팅 해주시기 바랍니다.','알림',MB_OK); end; finally FreeAndNil(FileStream); FreeAndNil(SD); end; Application.MessageBox('다운로드가 완료되었습니다.','알림',MB_OK); end;