자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 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 15767
공지 유용한 관련 사이트 관리자2 2014.03.20 54581
공지 본 게시판은 개발자 여러분들의 질문과 답변을 공유하는 공간입니다. 관리자 2012.01.10 97989
354 델파이 FireMonkey Sample&Help 별도 설치 관련 [2] 허준영 2018.05.04 408
353 Rio10.3.2 업그레이드 완료후 Getit Package Manager 접속오류 해소되었나요? [3] 델초보왕 2019.07.30 410
352 XE10 Seattle에서 DBExpress로 원격지 Firebird서버에 접속시 의문점입니다. [1] 김태윤 2016.03.16 410
351 크로스 컴파일 관련 문의 드립니다 에러나요~ [3] 해안건축 2015.03.13 412
350 롤리팝에서 프로그램이 구동되지 않습니다 [4] 위드유 2015.12.02 418
349 XE10 Rest컴포넌트를 이용한 멀티디바이스 앱에서 TFDMemTable관련 에러 [2] 김태윤 2016.03.21 418
348 파이어몽키 모바일 TEDIT 스캐너로 입력시 속도개선 방법 문의드립니다. [5] 파이어버드 2017.05.02 419
347 개발시 uses 절 관련 [1] 씨애틀 2016.03.08 422
346 Rad Studio Xe7 개발된 프로젝트 Delphi Xe7 에서 사용할때 문제점 [1] file 희망나라 2015.04.01 423
345 책장 넘기는 효과가 델파이에 있나요? [2] 슈퍼맨 2018.02.07 427
344 XE7 버그픽스 관련해서 문의드립니다. [2] Celsius 2015.05.18 428
343 FMX앱에서 던진 Intent를 Google Apps가 Intent를 받지 못합니다. [1] file Vincent 2017.11.14 431
342 BLE 페어링 [1] Brian 2017.09.14 433
341 CameraComponent에 대한 문의입니다. [1] arinh 2015.04.04 439
340 XE10 컴파일이 무한반복되는 현상에 대해 가을이다 2016.09.23 441
339 [10.4 시드니 신기능] 이제 리눅스 클라이언트 프로그램 개발이 윈도우처럼 가능합니까? 험프리 2020.06.10 448
338 TEdit 에 커서가 들어갈때 가상키보드 나타나지 않게 [2] 희망나라 2015.06.22 449
337 파이어몽키로 사진저장 파일오류...?? [1] 밤바야 2016.05.26 449
336 앱삭제시 데이타베이스도 삭제되나요.? [2] 희망나라 2018.11.06 453
335 카메라 권한을 runtime 시에 권한설정하려고 합니다. [3] 김하나 2017.02.28 457