자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 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 97984
1019 [공유] 라이브바인딩으로 날짜필드를 연결할때 포맷을 지정할 수 있나요? file 험프리 2015.10.21 389
1018 [세미나][DavidI] 윈도우 10 폰 타켓 플랫폼 지원 로드맵이 있나요? 험프리 2015.10.21 254
1017 [세미나][DavidI] MidaConverter를 이용한 프로젝트 변환과 비콘 연동에 대해 더 알고 싶습니다. 험프리 2015.10.21 121
1016 [세미나][DavidI] 이번 세미나에서 FireMonkey 새로운 기능에 대한 소개가 적어 아쉬웠습니다. 험프리 2015.10.21 127
1015 [세미나][DavidI] BeaconFence의 인식 범위는 어느정도까지 가능한가요? 험프리 2015.10.21 126
1014 [마이그레이션][델파이3>델파이10시애틀] Quick Report 마이그레이션 방법 알려주세요(마이그레이션 후 레포트 폼이 실행되지 않습니다.) [1] 박성민 2015.10.20 397
1013 [XE8] 안드로이드 이벤트 처리법 [1] 가을이다 2015.10.19 360
1012 XE8 WebBrowser컴포넌트 메모리 해제법 가을이다 2015.10.16 815
1011 비콘 블루투스 끊겼을때 exception 처리에 대해 devdevil0625 2015.10.16 264
1010 [마이그레이션] WinExec로 외부 실행파일 호출이 되지 않습니다. 험프리 2015.10.16 1543
1009 [마이그레이션][델파이 1~3] WinProcs.dcu, WinTypes.dcu not found 오류 발생 시 대처방법 험프리 2015.10.16 320
1008 [마이그레이션][팁] TServerSocket, TClientSocket 컴포넌트 추가 방법 험프리 2015.10.13 251
1007 FastReport 문의. [1] 회원 2015.10.12 1233
1006 델파이 xe5 firemonkey mobile Applicaton에서 Mediaplayer 사용 [6] superman 2015.10.11 894
1005 [XE8] 모바일개발시 스크롤뷰 감도 낮추는 방법 [1] 가을이다 2015.10.07 220
1004 사진앨범 접근, 사진 가져오기 [1] file 라드 2015.10.05 312
1003 delphi dx 및 er stduio 설치후 기존 버전 문제 [1] voyager 2015.10.12 147
1002 [마이그레이션][팁] 함수(또는 변수)에 빨간밑줄이 가고 컴파일 시 Undeclared Identifier 오류 시 조치방법 험프리 2015.10.12 148
1001 [마이그레이션][델파이4>2007] DBCtrlGrid에 DBLookupCombo를 올린 후 콤보를 선택하면 ""Operation not allowed in DBCtrlGrid"" 오류가 발생하고 목록이 표시되지 않습니다. 어떻게 해결해야하나요? 험프리 2015.05.30 403
1000 [마이그레이션] 델파이 XE8에서 체크박스, 라디오버튼의 글자의 색상을 변경하고 싶어요. 험프리 2015.06.10 1239