자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 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 15772
공지 유용한 관련 사이트 관리자2 2014.03.20 54588
공지 본 게시판은 개발자 여러분들의 질문과 답변을 공유하는 공간입니다. 관리자 2012.01.10 98012
33 LOCKBOX의 CODEC컴포넌트에서 AES 복호화시 유니코드 에러 입니다 ㅠ 돌떵이이11 2021.04.20 452
32 VB, FORTRAN 소스코드를 Delphi로 변환하는 방법이 있나요? [1] 험프리 2021.04.21 315
31 ios 앱 빌드 관련 문의 [2] 초보개발자 2021.05.03 516
30 [BRCC32 Error] "brcc32" exited with code 27. [3] file Dev_기어 2021.05.07 628
29 iOS에서 Android에서처럼 사용되는 Toast 질문입니다. [1] 랩실전기 2021.05.11 513
28 [마이그레이션] del7 소스를 10.2.3 tokyo prof. 에서 compile 도중 생긴 에러입니다. [2] darwin4078 2021.05.12 318
27 Delphi 7 REST Client 개발 문의 [2] DevCK 2021.05.12 822
26 XE7에서 bpl 컴포넌트 설치가 안됩니다. [1] 김동현 2021.05.13 456
25 본사 mypage [1] DHP 2021.05.17 2606
24 firedac 질문입니다 [2] 희망나라 2021.05.19 356
23 10.4 시드니에서 새로운 프로젝트 시작 오류 [2] file midas 2021.05.25 504
22 Delphi XE10.3의 TLabel이 Transparent가 안되는 문제 질문 [1] DevCK 2021.05.25 5001
21 Runtime error 216 at 5005F106 [2] 김동현 2021.05.28 495
20 mac os 개발 환결 세팅 관련 문의. [2] 델포이 2021.06.03 344
19 퀵리포트 -> PDF 변환 시 한글 깨짐 현상 질문입니다. [3] 으아앙 2021.06.03 828
18 Delphi 10.4 버전 맥용으로 컴파일시 오류 발생하는 이유가 궁금합니다. [2] 델포이 2021.06.04 346
17 C++ DLL 동적 배열을 어떻게 받아야 하나요? [1] 까막 2021.06.17 426
16 class EOleSysError 문제 file 김준수 2021.06.23 482
15 TFDConnection TimeOut [1] 지구수비방위대 2021.07.06 432
14 delphi 10.2 버전에서 크로미움으로 Chrome 브라우저를 사용중인데..mp4 같은 동영상이 실행이 안됩니다. [1] 미스터리 2021.07.11 1857