자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 Q&A 이용 (제품 구매 고객 한정)

궁금한 사항이 있어서 문의드립니다.

Delphi7과 Delphi XE에서 아래의 함수를 각각 실행해 보았을 때
Return(sT)값이 서로 틀리게 넘어오는데 
왜 그런지 확인 부탁드립니다.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  ComCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    IdTCPClient: TIdTCPClient;
    Button2: TButton;
    Button3: TButton;
    edtIp: TEdit;
    edtPort: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    lStatus: TPanel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

const
  STX = #$02;
  ETX = #$03;

  LF = #$0A; // Line Feed
  CR = #$0D; // Carriage Return
  SO = #$0E; // 확대적용
  SI = #$0F; // 확대취소


implementation

{$R *.DFM}

// CRC를 계산해 준다
function funGetCrc( lsData : String ) : String;
var crc,temp  : Word;
    lnI,lnJ,lnL : Integer;
    SEED : word;
begin

  SEED := $8005;
  crc  := $ffff;

  if Length(lsdata) = 0 then
  begin
    result := #$00#$00;
    Exit;
  end;

  lnL := length(lsData);

  for lnI := 1 to  lnL do
  begin
    temp := byte(lsData[lnI]) and $00ff;
    for lnJ := 1 to 8 do
    begin
      if  ((crc and $0001) xor (temp and $0001)) <> $0000 then
      begin
         crc := (crc shr 1) xor SEED;
      end else
      begin
         crc := (crc shr 1);
      end;
      temp := (temp shr 1);
    end;
  end;

  result := chr(low(Temp)) + chr(low(crc)) ;

  crc    := not crc;
  temp   := crc;
  crc    := (crc shl 8) or ((temp shr 8) and $00ff);

  temp   := (crc shr 8);
  crc    := (crc shl 8);
  crc    := (crc shr 8);

  result := chr(Temp) + chr(crc);

end;


function funMakePrt( PrtFileName, PrtData : String ) : String;
var
  sT : String;
  iT : integer;
begin
  SetLength(sT,17);
  FillChar(Pointer(sT)^,17,' ');
  Move(Pointer(PrtFileName)^,Pointer(sT)^,Length(PrtFileName));

  sT := sT + FormatFloat('0000',Length(PrtData)) + PrtData ;
  iT := Length(sT);
  sT := Chr((iT shr 8)) + Chr((iT and $ff)) + 'P' + sT + #$03;

  Result := #$02 + sT + funGetCrc(sT);
end;




procedure TForm1.Button1Click(Sender: TObject);
var
  Command: string;
  sSendStr: string;
  sPrtFileName: string;
begin
  Command := 'C' + CR + LF;
  Command := Command + 'T110' + '일반' + CR + LF;
  Command := Command + 'T110' + SO + '가로확대' + SI + CR + LF;
  Command := Command + 'T110' + SO + '세로확대' + SI + CR + LF;
  Command := Command + 'T110' + SO + '가로세로확대' + SI + CR + LF;
  Command := Command + 'L50' + CR + LF; // 라인피드 5회
  Command := Command + 'PC' + CR + LF; // 프린트 & 컷팅

  sPrtFileName := 'A123456' + FormatDatetime('MMddhhmmss',Now);

// 1.  델파이7에서 실행했을 때와 델파이 XE에서 실행했을 때의 함수 리턴값(=sSendStr)이 서로 틀립니다.
  sSendStr := funMakePrt(sPrtFileName, Command);

// 2. 아래의 코드를 XE에서 실행하면 오류가 발생을 하는데
//   XE에서 실행하려 하면 어떻게 변경해야 하는지요.. 
  IdTcpClient.Socket.Send(pointer(sSendStr)^,length(sSendStr));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  with IdTcpClient do
  begin
    Host := edtIp.Text;
    Port := StrToInt(edtPort.Text);
    try
      Connect;
      if Connected then
      begin
        lStatus. Caption := '연결성공';
      end;
    except
      MessageDlg('TS-163N 단말기 연결 실패', mtInformation, [mbOk], 0);
    end;
  end;

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
//  IdTcpClient.Socket.InputBuffer.Clear;
  IdTcpClient.Disconnect;
  lStatus.Caption := '';

end;

end.

번호 제목 글쓴이 날짜 조회 수
공지 [프로그래밍 강의] 2021.6~2021.12 관리자 2015.01.22 15766
공지 유용한 관련 사이트 관리자2 2014.03.20 54580
공지 본 게시판은 개발자 여러분들의 질문과 답변을 공유하는 공간입니다. 관리자 2012.01.10 97985
939 [IoT 세미나] 블루투스에 대해 알고 싶습니다. Humphery 2015.09.04 112
938 [IoT 세미나] 병원에서의 IoT 활용 예제를 알고싶어요. Humphery 2015.09.04 260
937 [IoT 세미나] 비콘의 UUID, Major, Minor를 제외하고 인식할 수 있는 다른 정보가 있나요? Humphery 2015.09.04 889
936 [IoT 세미나] 비콘이 발생하는 데이터의 크기는 얼마나 되나요? Humphery 2015.09.03 122
935 [IoT 세미나] 비콘이 사용자를 인식할 수는 없나요? Humphery 2015.09.03 175
934 [IoT 세미나] 비콘 배터리는 얼마나 가나요? Humphery 2015.09.03 476
933 .so 로드가 안됩니다 [1] 라드 2015.09.03 214
932 iOSapi.AssetsLIbrary를 이용해 ios의 앨범 목록을 가져오고 싶습니다. [2] file Celsius 2015.08.13 403
931 아이폰 TTS 예제.. 가을이다 2015.09.03 328
930 아이폰 개발(환경) [2] 가을이다 2015.09.03 568
929 문자전송기능?? [2] syc 2015.09.02 245
928 PAServer SDK 설정 및 디버깅 관련 오류 [1] 릴리리 2015.09.02 248
927 재문의 - Beacon, Bluetooth, Bluetooth LE 동시 접속 문의 [3] 이정이남편 2015.08.26 1128
926 카카오톡 REST API 사용 관련해서 여쭈어 봅니다. [2] 유탐호호 2015.08.31 2470
925 재문의-data snap utf8 관련 오류 [3] file 사랑남 2015.08.29 242
924 현재 XE8로 지원되는 스마트워치 종류를 알고싶습니다. [1] 가을이다 2015.08.27 661
923 미들웨어 서버컴퓨터에 구축하는방법 질문드려요.. [1] syc 2015.08.29 332
922 data snap utf8 관련 오류 [2] file 사랑남 2015.08.26 136
921 ios 앱 외부 url 호출 방법 문의 [1] 사랑남 2015.08.28 336
920 재질문_하이브리드 앱 종료 방법문의 [1] 사랑남 2015.08.26 208