자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 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 15766
공지 유용한 관련 사이트 관리자2 2014.03.20 54580
공지 본 게시판은 개발자 여러분들의 질문과 답변을 공유하는 공간입니다. 관리자 2012.01.10 97985
334 xe7에서 마쉬멜로 6.0.1 버전 빌드시에 [2] 손인호 2016.07.20 215
333 MultiView에서 MultiDetail3.InternalPlaceOffset.X 를 수정할 수가 없네요. 어려워 2016.07.17 133
332 비콘 감지중 블루투스를 사용자가 강제로 off시 어떻게 처리해야 할까요? 김태윤 2016.07.15 681
331 ios 한글이 깨집니다. (같은 환경에서 안드로이드는 잘 됩니다) file 어려워 2016.07.14 291
330 DICOM 포맷을 핸들링할 수 있는 파이어몽키(FMX) 컴포넌트가 있나요? [1] 관리자 2016.07.11 593
329 안드로이드 ViewPager 구현 문의 [2] file 손주영 2016.07.08 317
328 안드로이드 서비스에서 비콘감지 김태윤 2016.07.11 539
327 Tools->Options->Provisioning 에 들어가면 ... file 어려워 2016.07.09 145
326 MemoryStream 문의입니다 [2] file 최민철 2015.09.08 654
325 안드로이드 플랫폼에서 jpg, png파일 포맷 사용하려면 [2] superman 2016.06.15 736
324 [시애틀]디버그 모드 진입 불가 [1] 김태윤 2016.06.14 403
323 [시애틀]비콘을 안드로이드 서비스로 감지하는데 자꾸 응답없음으로 강제종료됩니다. [2] 김태윤 2016.06.09 526
322 firemonkey로 window와 mac OS 를 개발하는 중입니다. 모바일과 푸쉬를 주고 받을수 있는지 궁금합니다. [1] 운땡최향태 2016.05.31 146
321 안드로이드 디버깅이 재대로 실행되지 않습니다. [3] hsson 2016.06.03 408
320 Xe5에서 안드로이드 버전 얼마까지 지원되나요? [1] 농가사랑 2016.06.01 193
319 안드로이드 서비스(백그라운드 실행)에서 특정 상황에서 앱자동 실행 [2] 김태윤 2016.05.24 2839
318 ListBox Item Style내부 색상변경 [2] 박군80 2016.05.24 601
317 OSX 개발시 ICON 가져오기 freehun 2016.05.27 122
316 안드로이드 블루투스 한글 관련 질문 [1] hsson 2016.05.13 391
315 안드로이드 비트맵 최대크기관련 질문. [1] hsson 2016.05.26 387