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

기존 VCL프로그램을 firemonkey로 변환중입니다.

문제가 여러곳에서 발생하는데 원인을 모르겠어서 이렇게 질문 올립니다.

 

아참 그리고 _String8은 AnsiString 입니다.

 

Ex8에서 작업중이고요

AnsiString은 ByteStrings이용해서 사용중입니다.

---------------------------------------------------------------------------------------------------------------------

오류 내용

---------------------------------------------------------------------------------------------------------------------

[DCC Error] hDataUtil.pas(756): E2581 Backend error: Stored value type does not match pointer operand type!
  store i32 1, i8* %17, !dbg !378
 i8Stored value type does not match pointer operand type!
  store i32 1, i8* %30, !dbg !378
 i8Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Stored value type does not match pointer operand type!
  store i32 1, i8* %58, !dbg !395
 i8Stored value type does not match pointer operand type!
  store i32 1, i8* %64, !dbg !395
 i8Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.

 

 

---------------------------------------------------------------------------------------------------------------------

소스코드

---------------------------------------------------------------------------------------------------------------------
unit hDataUtil;

interface
uses
    SysUtils, DateUtils, StrUtils,
    hType, System.Types, System.UITypes,
    System.Classes, System.Variants;

type
    //Different numbering system enumeration
    TNumSys = (nsBin, nsOct, nsDec, nsHex);
const
    //Extended characters to represent hex numbering system
    DigitList :_String8 = '0123456789ABCDEF';

    function    Iif(Condition: Boolean; TrueValue, FalseValue: variant): variant;
    function    isDigit(c: Char) : Boolean;
    function    StrIn(Org: string; Cmp : array of string): Integer;
 procedure   AddUniqueString(var Origin: string; Wanted: string);
    function    MakeFixedSizeString(Str: string; FixedSize: Integer;
                        Padding: Char): string;
 function IntToStr0(i, zero: Integer): string;
    function    WordToHex(AWord: Word; AReverseOrder : Boolean = False): string;
    function    AsciiHexToStr(Str: _string8): _string8; overload;
    function    AsciiHexToStr(Str: _string8; SplitByte: Integer): _string8; overload;
    function    getHexData(buf1, buf2: _Char8; var Res: Byte) : Boolean;
    function    getHexStrData(b: Byte): _String8;
    function    ByteToBinStr(x: Byte): string;
    function    StrToAsciiHex(Str: _string8): _string8; overload;
    function    StrToAsciiHex(Str, Spliter: _string8): _string8; overload;
    function    HexVarDataToStr(str: string): VarTypeConvStr;
    function    DecVarDataToStr(str: string): VarTypeConvStr;

    function    GetFValueFromStr(Data: _String8; Offset: Integer): Single;
    function    hasHeaderTail(var APacket: string; APrefix, ASuffix: string;
                                var AResult: string): Boolean;
    function    calcXor(Str: _String8): Byte;
    function    calcChecksum(Str: _String8): Byte;
    function    calcCRC16(Str: _String8): Word;
    function    CRC16Str(Str: _String8): _string8;
    function    SwapWord(Data: Word): Word;
    function    IntToStrNum(Value: Cardinal; const OutNumSys: TNumSys;
                    Digits: Integer): _string8;
implementation

const
{* High-Order Byte table *}
CRCHiTable : array[0..255] of Byte = (
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $01,$C0,$80,$41,$00,$C1,$81,$40,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $00,$C1,$81,$40,$01,$C0,$80,$41,
     $01,$C0,$80,$41,$00,$C1,$81,$40
);

{ Low-Order Byte table }
CRCLoTable : array[0..255] of Byte = (
     $00,$C0,$C1,$01,$C3,$03,$02,$C2,
     $C6,$06,$07,$C7,$05,$C5,$C4,$04,
     $CC,$0C,$0D,$CD,$0F,$CF,$CE,$0E,
     $0A,$CA,$CB,$0B,$C9,$09,$08,$C8,
     $D8,$18,$19,$D9,$1B,$DB,$DA,$1A,
     $1E,$DE,$DF,$1F,$DD,$1D,$1C,$DC,
     $14,$D4,$D5,$15,$D7,$17,$16,$D6,
     $D2,$12,$13,$D3,$11,$D1,$D0,$10,
     $F0,$30,$31,$F1,$33,$F3,$F2,$32,
     $36,$F6,$F7,$37,$F5,$35,$34,$F4,
     $3C,$FC,$FD,$3D,$FF,$3F,$3E,$FE,
     $FA,$3A,$3B,$FB,$39,$F9,$F8,$38,
     $28,$E8,$E9,$29,$EB,$2B,$2A,$EA,
     $EE,$2E,$2F,$EF,$2D,$ED,$EC,$2C,
     $E4,$24,$25,$E5,$27,$E7,$E6,$26,
     $22,$E2,$E3,$23,$E1,$21,$20,$E0,
     $A0,$60,$61,$A1,$63,$A3,$A2,$62,
     $66,$A6,$A7,$67,$A5,$65,$64,$A4,
     $6C,$AC,$AD,$6D,$AF,$6F,$6E,$AE,
     $AA,$6A,$6B,$AB,$69,$A9,$A8,$68,
     $78,$B8,$B9,$79,$BB,$7B,$7A,$BA,
     $BE,$7E,$7F,$BF,$7D,$BD,$BC,$7C,
     $B4,$74,$75,$B5,$77,$B7,$B6,$76,
     $72,$B2,$B3,$73,$B1,$71,$70,$B0,
     $50,$90,$91,$51,$93,$53,$52,$92,
     $96,$56,$57,$97,$55,$95,$94,$54,
     $9C,$5C,$5D,$9D,$5F,$9F,$9E,$5E,
     $5A,$9A,$9B,$5B,$99,$59,$58,$98,
     $88,$48,$49,$89,$4B,$8B,$8A,$4A,
     $4E,$8E,$8F,$4F,$8D,$4D,$4C,$8C,
     $44,$84,$85,$45,$87,$47,$46,$86,
     $82,$42,$43,$83,$41,$81,$80,$40
);

//------------------------------------------------------------------------------
// iif :: Evaluate and select one
//------------------------------------------------------------------------------
function Iif(Condition: Boolean; TrueValue, FalseValue: variant): variant;
begin
    if Condition then Result := TrueValue
    else Result := FalseValue;
end;

//----------------------------------------------------------------------------------------
// is_digit :: check c is number
//----------------------------------------------------------------------------------------
function isDigit(c: Char): Boolean;
begin
    Result := (c in ['0' .. '9']);
end;
//------------------------------------------------------------------------------
// StrIn :: Check a string in "Array Of string"
//------------------------------------------------------------------------------
function StrIn(Org: string; Cmp: array of string): Integer;
var
    i: Integer;
begin
    Result := -1;
    for i := Low(Cmp) to High(Cmp) do
        if Trim(Org) = Trim(Cmp[i]) then
        begin
            Result := i;
            break;
        end;
end;

//------------------------------------------------------------------------------
// AddUniqueString :: Combines two string where contains unique characters
//------------------------------------------------------------------------------
procedure AddUniqueString(var Origin: string; Wanted: string);
var
    i: Integer;
begin
    for i := 1 to Length(Wanted) do
        if Pos(Wanted[I], Origin) = 0 then
            Origin := Origin + Wanted[i];
end;

//------------------------------------------------------------------------------
// MakeFixedSizeString :: Make a string to fixed size
//                          (if short, padding some character)
//------------------------------------------------------------------------------
function MakeFixedSizeString(Str: string; FixedSize: Integer;
                                Padding: Char): string;
var
    Len : Integer;
begin
    Len := Length(Str);
    if (Len > FixedSize) then
        Result := Copy(Str, 1, FixedSize)
    else if Len < FixedSize then
        Result := Str + StringOfChar(Padding, FixedSize - Len)
    else
        Result := Str;
end;

//----------------------------------------------------------------------------------------
// IntToStr0 :: fill zero before i as 'Zero' count
//               - 의 경우는....1자리가 더 늘어남...
//----------------------------------------------------------------------------------------
function IntToStr0(i, Zero: Integer): string;
var
    s       : string;
    z, l    : Integer;
begin
    s := IntToStr( abs(i) );
    l := Zero - Length(s);
    if (l > 0) then
    begin
        for z := 1 to l do
            s := '0' + s;
    end;
    if (i < 0) then s := '-' + s;
    Result := s;
end;

//------------------------------------------------------------------------------
// WordToHex :: Get hex string 2 byte from Word order by AReverseOrder
//------------------------------------------------------------------------------
function WordToHex(AWord: Word; AReverseOrder: Boolean): string;
begin
    if AReverseOrder then
    begin
        // Low byte, High byte representation
        Result := _Char8(AWord and $FF);
//        Result := Result + Chr(AWord shr 8);
        Result := Result + _Char8( (AWord and $FF00) shl 8 );
    end
    else
    begin
        // High byte, Low byte representation
//        Result := Chr(AWord shr 8);
        Result := _Char8( (AWord and $FF00) shl 8 );
        Result := Result + _Char8(AWord and $FF);
    end;
end;

//------------------------------------------------------------------------------
// AsciiHexToStr :: return hex to ascii c
//------------------------------------------------------------------------------
function AsciiHexToStr(Str: _string8): _string8;
var
   i   : Integer;
   Conv: Byte;
   tmp : string;
   Len : Integer;
begin
    Result  := '';
    i       := 1;
    Len     := Length(Str);
    while i <= (Len - 1) do
    begin
        if((Str[i] in ['0'..'9', 'A'..'F', 'a'..'f'])
            and (Str[i + 1] in ['0'..'9', 'A'..'F', 'a'..'f'])) then
        begin
//            tmp := '$' + Str[i] + Str[i + 1];
//            Conv := StrToInt(tmp);
            getHexdata(Str[i], Str[i + 1], Conv);
            Result := Result + _Char8(Conv);
            i := i + 1;
        end;
        i := i + 1;
    end;
end;

//------------------------------------------------------------------------------
// AsciiHexToStr :: return string to convert ascii to hexa
//------------------------------------------------------------------------------
function AsciiHexToStr(Str: _string8; SplitByte: Integer): _string8;
var
   i   : Integer;
   Conv: Integer;
   tmp : string;
   Len : Integer;
begin
    Result  := '';
    i       := 1;
    Len     := Length(Str);
    while i <= (Len - 1) do
    begin
        if((Str[i] in ['0'..'9', 'A'..'F', 'a'..'f'])
            and (Str[i + 1] in ['0'..'9', 'A'..'F', 'a'..'f'])) then
        begin
            tmp := '$' + Str[i] + Str[i + 1];
            Conv := StrToInt(tmp);
            Result := Result + _Char8(Conv);
            i := i + 2;
        end;
        i := i + SplitByte;
    end;
end;


//
// 두바이트 아스키 data를 byte로 변경...
//
function getHexData(buf1, buf2: _Char8; var Res: Byte) : Boolean;
var
    b1, b2 : Byte;
begin
    b1 := Pos(UpperCase(_string8(buf1)), DigitList);
    b2 := Pos(UpperCase(_string8(buf2)), DigitList);
    if( (b1 > 0) and (b2 > 0) )then
    begin
        Res := ((b1 - 1) shl 4) or (b2 - 1);
        Result := True;
    end
    else begin
        Res := $FF;
        Result := False;
    end;
end;

//
// byte를 두바이트 아스키로 변경
//
function getHexStrData(b: Byte): _String8;
begin
    Result := DigitList[((b and $F0) shr 4) + 1] + DigitList[(b and $0F) + 1];
end;


//------------------------------------------------------------------------------
// ByteToBinStr :: return string to convert byte to binary
//------------------------------------------------------------------------------
function ByteToBinStr(x: Byte): string;
var
    i: Integer;
begin
    Result :='';
    for i := 0 to 8 do
        if (((1 shl i) and x ) = 0) then
            Result := '0' + Result
        else
            Result := '1' + Result;
end;

//------------------------------------------------------------------------------
// StrToAsciiHex :: return string to convert decial (as string) to hex
//------------------------------------------------------------------------------
function StrToAsciiHex(Str: _string8): _string8;
var
   i: Integer;
begin
    Result := '';
    for i := 1 to Length(Str) do
        Result := Result + IntToHex(Ord(Str[i]), 2) + ' ';
end;

//------------------------------------------------------------------------------
// StrToAsciiHex :: return string to convert decial (as string) to hex with spliter
//------------------------------------------------------------------------------
function StrToAsciiHex(Str, Spliter: _string8): _string8;
var
   i: Integer;
begin
    Result := '';
    for i := 1 to Length(Str) do
        Result := Result + IntToHex(Ord(Str[i]), 2) + Spliter;
end;

//------------------------------------------------------------------------------
// VarDataToStr :: change varialbes to string
//------------------------------------------------------------------------------
function VarDataToStr(Data: VarTypeConv; ChkByte : Integer; isInt : Boolean = False): VarTypeConvStr;
var
    sVarSignedByte      : string;
    sVarUnsignedByte    : string;
    sVarSignedShort     : string;
    sVarUnsignedShort   : string;
    sVarSignedInt       : string;
    sVarUnsignedInt     : string;
    sVarSignedInt64     : string;
    sVarUnsignedInt64   : string;
    sVarFloat           : string;
    sVarDouble          : string;
    sVarDateTimeStr     : string;
    sVarUnixTimeGMT     : string;
    sVarUnixTime        : string;

    sData               : VarTypeConvStr;
    t                   : TDateTime;
    UnixTime            : Int64;

begin

    if((ChkByte and $1) = $1) then
    begin
        sVarSignedByte      := IntToStr(Data.VarSignedByte);
        sVarUnsignedByte    := IntToStr(Data.VarUnsignedByte);
    end;
    if((ChkByte and $2) = $2) then
    begin
        sVarSignedShort     := IntToStr(Data.VarSignedShort);
        sVarUnsignedShort   := IntToStr(Data.VarUnsignedShort);
    end;
    if((ChkByte and $4) = $4) then
    begin
        sVarSignedInt       := IntToStr(Data.VarSignedInt);
        sVarUnsignedInt     := IntToStr(Data.VarUnsignedInt);
        sVarFloat           := FloatToStr(Data.VarFloat);
    end;
    if((ChkByte and $8) = $8) then
    begin
        sVarDouble          := FloatToStr(Data.VarDouble);
        sVarSignedInt64     := IntToStr(Data.VarSignedInt64);
        sVarUnsignedInt64   := IntToStr(Data.VarUnsignedInt64);
        //t                   := Data.VarDateTime;
        t                   := iif(isInt, Data.VarSignedInt64, Data.VarDateTime);

        sVarDateTimeStr     := FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', t);
        if(isInt) then
        begin
            UnixTime            := Data.VarSignedInt64;
            if(UnixTime >= 0) then
            begin
                sVarUnixTimeGMT     := FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', UnixToDateTime(UnixTime) );
                sVarUnixTime        := FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', UnixToDateTime(UnixTime + 3600*9) );
            end;
        end;
    end;

    sData.sVarSignedByte      :=     sVarSignedByte;
    sData.sVarUnsignedByte    :=     sVarUnsignedByte;
    sData.sVarSignedShort     :=     sVarSignedShort;
    sData.sVarUnsignedShort   :=     sVarUnsignedShort;
    sData.sVarSignedInt       :=     sVarSignedInt;
    sData.sVarUnsignedInt     :=     sVarUnsignedInt;
    sData.sVarSignedInt64     :=     sVarSignedInt64;
    sData.sVarUnsignedInt64   :=     sVarUnsignedInt64;
    sData.sVarFloat           :=     sVarFloat;
    sData.sVarDouble          :=     sVarDouble;
    sData.sVarDateTimeStr     :=     sVarDateTimeStr;
    sData.sVarUnixTimeGMT     :=     sVarUnixTimeGMT;
    sData.sVarUnixTime        :=     sVarUnixTime;

    Result := sData;
end;


//------------------------------------------------------------------------------
// HexVarDataToStr :: change varialbes to string
//------------------------------------------------------------------------------
function HexVarDataToStr(str: string): VarTypeConvStr;
var

    Data                : VarTypeConv;
    DataLength          : Integer;
    i                   : Integer;
    tmp                 : Byte;
begin

    //DataLength := GetHexByteLength(edInputHex.Text);

    i := 1;
    DataLength := 0;
    while (i < Length(str)) do
    begin
        if( (str[i] in ['0'..'9', 'A'..'F', 'a'..'f'])
            and (str[i + 1] in ['0'..'9', 'A'..'F', 'a'..'f']) )then
        begin
            DataLength := DataLength + 1;
            if(DataLength <= 8) then
            begin
                tmp := StrToInt('$' + str[i] + str[i + 1]);
                Data.VarArrayByte[DataLength] := tmp;
            end;
            i := i + 2;
        end
        else begin
            i := i + 1;
        end;
    end;

    if(DataLength = 1) then DataLength := 1
    else if(DataLength = 2) then

    if(DataLength > 1) then DataLength := DataLength or 1;
    if(DataLength > 2) then DataLength := DataLength or 2;
    if(DataLength > 4) then DataLength := DataLength or 4;
    if(DataLength > 8) then DataLength := DataLength or 8;

    Result := VarDataToStr(Data, DataLength);
  end;

//------------------------------------------------------------------------------
// DecVarDataToStr :: change varialbes to string
//------------------------------------------------------------------------------
function DecVarDataToStr(str: string): VarTypeConvStr;
var
    Data                : VarTypeConv;
    tmp                 : Int64;
//    tmp2                : Double;
    tmp2                : Single;
    isInt               : Boolean;
    Loc                 : Integer;
begin
    Loc := Pos('.', str);
    if (Loc = 0) then
    begin
        tmp := StrToInt64Def(str, 0);
        Data.VarSignedInt64 := tmp;
        isInt := True;
    end
    else begin
        tmp2 := StrToFloatDef(str, 0);
//        Data.VarDouble := tmp2;
        Data.VarFloat:= tmp2;
        isInt := False;
    end;

    Result := VarDataToStr(Data, $F, isInt);
end;

//------------------------------------------------------------------------------
// GetFValueFromStr :: return float to change string type to single type
//------------------------------------------------------------------------------
function GetFValueFromStr(Data: _String8; Offset: Integer): Single;
var
    fStr : string;
    //fValue : Single;
    fValue : VarTypeConv;

begin
    //fstr := Copy(Data, Offset, 4);
    fValue.VarArrayByte[1] := Ord(Data[1 + Offset]);
    fValue.VarArrayByte[2] := Ord(Data[2 + Offset]);
    fValue.VarArrayByte[3] := Ord(Data[3 + Offset]);
    fValue.VarArrayByte[4] := Ord(Data[4 + Offset]);

    //vardatatostr(fValue,4);


   // fstr := Copy(Data, Offset, 4);
   // move(fstr[1], fValue, 4);

    Result := fValue.VarFloat;
end;

//------------------------------------------------------------------------------
// AnalysisPacket :: check whether packet has prefix and suffix
//                  and remove prefix and suffix
//------------------------------------------------------------------------------
function hasHeaderTail(var APacket: string; APrefix, ASuffix: string;
                var AResult: string): Boolean;
var
    PrefixPos, SuffixPos : Integer;
begin
    AResult     := '';
    Result      := False;
    // Save Prefix position
    PrefixPos   := Pos(APrefix, APacket);
    // Save Suffix position
    SuffixPos   := Pos(ASuffix, APacket);

    if PrefixPos > 0 then
    begin
        // Drop garbage data before valid packet
        APacket := MidStr(APacket, PrefixPos, Length(APacket));
        // If packet incomplete now, wait next time
        if SuffixPos > 0 then
        begin
            // If Prefix, Suffix in a valid sequence,
            if PrefixPos < SuffixPos Then
            begin
                // -> Valid packet (Include APrefix, ASuffix)
                AResult := MidStr(APacket, 1, SuffixPos + Length(ASuffix) - 1);
                // -> Drop APrefix, ASuffix @ AResult
                AResult := MidStr(AResult, Length(APrefix) + 1,
                                Length(AResult) - Length(APrefix) - Length(ASuffix));
                Result  := True;
            end;
            // -> Clear packet (Only one command can be proceed in a sequence)
            APacket := '';
        end;
    end
end;

//------------------------------------------------------------------------------
// calcXor :: return byte to calc xor
//------------------------------------------------------------------------------
function calcXor(Str: _String8): Byte;
var
    i: Integer;
begin
    if(Length(Str) > 0) then
    begin
        Result := Ord(Str[1]);
        for i := 2 to Length(Str) do
            Result := Result xor Ord(Str[i]);
    end
    else begin
        Result := 0;
    end;
end;

//------------------------------------------------------------------------------
// calcChecksum return checksum byte
//------------------------------------------------------------------------------
function calcChecksum(Str: _String8): Byte;
var
    i: Integer;
begin
    Result := 0;
    for i := 1 to Length(Str) do
        Result := Result + Ord(Str[i]);
end;

//------------------------------------------------------------------------------
// calcCRC16 :: return crc16 as word
//------------------------------------------------------------------------------
function calcCRC16(Str: _String8): Word;
var
    uchCRCHi: Byte;
    uchCRCLo: Byte;
    uIndex,i: Word;
    nDataLen: Word;
begin
    uchCRCHi := $FF;
    uchCRCLo := $FF;
    nDataLen := Length(Str);

    for i := 1 to nDataLen do
    begin
        uIndex   := uchCRCHi xor Byte(Str[i]);
        uchCRCHi := uchCRCLo xor CRCHiTable[uIndex];
        uchCRCLo := CRCLoTable[uIndex];
    end;

    Result := (uchCRCHi shl 8 or uchCRCLo);
end;

//------------------------------------------------------------------------------
// CRC16Str :: return crc16 as string
//------------------------------------------------------------------------------
function CRC16Str(Str: _String8): _String8;
var
    uchCRCHi: Byte;
    uchCRCLo: Byte;
    uIndex,i: Word;
    nDataLen: Word;
begin
    uchCRCHi := $FF;
    uchCRCLo := $FF;
    nDataLen := Length(Str);

    for i := 1 to nDataLen do
    begin
        uIndex   := uchCRCHi xor Byte(Str[i]);
        uchCRCHi := uchCRCLo xor CRCHiTable[uIndex];
        uchCRCLo := CRCLoTable[uIndex];
    end;

    Result := _Char8(uchCRCLo) + _Char8(uchCRCHi);
//    Result := Chr(uchCRCHi) + Chr(uchCRCLo);
end;

//------------------------------------------------------------------------------
// SwapWord :: Swap word
//------------------------------------------------------------------------------
function    SwapWord(Data: Word): Word;
begin
    Result := (Data shr 8) + ((Data and $FF) shl 8);
end;

{
Returns the numerical value of the input numbering system
@param NumSys the numbering system
@result the base of the numbering system
}
{$WARNINGS OFF}
function GetBase(const NumSys: TNumSys): Integer;
begin
case NumSys of
    nsBin: Result := 2;
    nsOct: Result := 8;
    nsDec: Result := 10;
    nsHex: Result := 16;
end;
end;
{$WARNINGS ON}

{
Adds leading '0' characters to a string
@param S the source string
@param Count the amount of '0's to add
@result The newly formatted string with leading '0's
}
function AddLeadingZeros(const S: String; Count: Integer): String;
var
    k: Integer;
begin
    Result := '';
    for k := 1 to Count do
        Result := Result + '0';
    Result := Result + S;
end;

{
Sets the minimum number of digits in a string. If Count > the current length
of S then the result is filled by '0' character from the left.
@param S the source string
@param Count the length of the result string
@result the newly sized string
}
function SetDigitCount(const S: String; Count: Integer): String;
var
    NewString: String;
begin
    NewString := S;
    if Length(S) < Count then
        NewString := AddLeadingZeros(S, Count - Length(S));
    Result := NewString;
end;

{
Converts an intger value to a string representation of a numerical value
in a specified numbering system.
@param Value the input integer value to convert
@param OutNumSys the output numbering system of the result
@param Digits the minimum number of digits for the result
@result the string representation of Value in a specified numbering system
}
function IntToStrNum(Value: Cardinal; const OutNumSys: TNumSys;
                        Digits: Integer): _string8;
var
    Base: Cardinal;
begin
    if Value = 0 then
    begin
        Result := SetDigitCount('0', Digits);
        Exit;
    end;

    Result := '';
    Base := GetBase(OutNumSys);

    //Determine the digit character for every character position in the number
    //text representation and add it to Result
    while Value > 0 do
    begin
        Result := DigitList[(Value mod Base) + 1] + Result;
        Value := Value div Base;
    end;

    Result := SetDigitCount(Result, Digits);
end;

end.

 

 

번호 제목 글쓴이 날짜 조회 수
공지 [프로그래밍 강의] 2021.6~2021.12 관리자 2015.01.22 15759
공지 유용한 관련 사이트 관리자2 2014.03.20 54576
공지 본 게시판은 개발자 여러분들의 질문과 답변을 공유하는 공간입니다. 관리자 2012.01.10 97972
354 datasnap 레코드수정방법 문의드립니다 천년바우 2016.10.17 120
353 델파이 시애틀로 만든 안드로이드앱을 ios버전으로 컴파일시 에러 문의 [1] 김태윤 2016.10.13 280
352 아이폰 앱개발 환경설정 문의 [2] 김태윤 2016.10.06 523
351 앱 디플로이 시 디버그 정보를 False로 어떻게 바꿉니까? [2] 푸른솔 2016.10.04 702
350 XE7 Android 6.0 실행시 문제.. [1] 손인호 2016.09.24 126
349 XE10 컴파일이 무한반복되는 현상에 대해 가을이다 2016.09.23 418
348 XE10,1 berlin android 설정 [1] 푸우웅 2016.09.19 361
347 stringgrid 숫자 왼쪽정렬 문의 [2] file 천년바우 2016.09.19 461
346 TBeacon컴포넌트사용시 모바일 배터리 소모에대해 김태윤 2016.09.13 152
345 안드로이드 앱 Signing 여부를 어떻게 알수 있습니까? [1] file 푸른솔 2016.09.09 166
344 XE8로 만든 어플실행시 꺼짐현상 [1] 흠흠흠 2016.09.05 545
343 디버깅 방법 문의드립니다. 엘타 2016.08.27 119
342 이런 디자인은 어떤 콤포넌트와 스타일을 사용해야 할까요? [2] file 화이부동 2016.08.16 154
341 TEdit 박스 한글로 선택후 입력시 선택된 문자를 덮어쓰지 않는 문제 [5] file 운땡최향태 2016.08.04 746
340 웹브라우저로 네이버 로그인을 하려고하는데 어떻게해야되나요 ? 머호로 2016.08.14 146
339 Connection Closed Gracefully [4] file 박군80 2016.07.27 2507
338 jar파일을 이용해 안드로이드 용 콤포넌트 등록을 하려고 합니다 [2] file 푸른솔 2016.08.02 362
337 TBeacon컴포넌트의 속성중 시간값관련속성의 정확한 쓰임새가 궁금합니다. [2] 김태윤 2016.07.18 156
336 ios에서는 문자메세지를 어떻게 보내나요? [2] 어려워 2016.07.19 589
335 TBeacon 비동기I/O관련 질문입니다. [1] 김태윤 2016.07.19 110