자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 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 15796
공지 유용한 관련 사이트 관리자2 2014.03.20 54604
공지 본 게시판은 개발자 여러분들의 질문과 답변을 공유하는 공간입니다. 관리자 2012.01.10 98036
59 Android 컴파일 오류 [2] file 초보개발자 2021.04.07 411
58 delphi7에서 dbe를 이용한 mssql에서 저장프로시져 호출하여 작업하면 이상없는데. xe10.4에서 fireDAC을 이요하면 멈춤 추도사 2021.04.08 358
57 C#에서 만든 DLL 사용 가능 합니까? [1] midas 2021.04.12 1130
56 code insight Auto invoke 기능 질문합니다. LYNN 2021.04.12 217
55 사용자 컴포넌트 추가를 해도 tool Palette에 보이지 않음 [1] file 추도사 2021.04.14 248
54 10.4.2 코드인사이트 기능에 대해 [1] file delphiman 2021.04.16 383
53 FireDac Transaction 문의 [2] BD 2021.04.19 1116
52 윈도우 키오스크에서 손가락으로 TImage 의 Canvas에 선 그리는 방법 [1] file 미스터몽키 2021.04.19 576
51 LOCKBOX의 CODEC컴포넌트에서 AES 복호화시 유니코드 에러 입니다 ㅠ 돌떵이이11 2021.04.20 453
50 VB, FORTRAN 소스코드를 Delphi로 변환하는 방법이 있나요? [1] 험프리 2021.04.21 315
49 사용자 컴포넌트 제작하는 방법이 있나요? [1] 하얀돌고래 2021.04.26 13340
48 FireDAC을 사용한 MySQL관련 입니다. [2] file 오늘도좋은하루 2021.04.28 375
47 ios 앱 빌드 관련 문의 [2] 초보개발자 2021.05.03 516
46 IOS 새로고침 드래그시 이슈 delphiman 2021.05.06 232
45 [BRCC32 Error] "brcc32" exited with code 27. [3] file Dev_기어 2021.05.07 631
44 애플 인증서 오류 관련하여 문의드립니다. [3] file delphiman 2021.05.11 3856
43 iOS에서 Android에서처럼 사용되는 Toast 질문입니다. [1] 랩실전기 2021.05.11 513
42 [마이그레이션] del7 소스를 10.2.3 tokyo prof. 에서 compile 도중 생긴 에러입니다. [2] darwin4078 2021.05.12 319
41 Delphi 7 REST Client 개발 문의 [2] DevCK 2021.05.12 822
40 png Image Button에서 Flickering문제 [5] 오늘도좋은하루 2021.05.12 516