자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 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 17220
공지 유용한 관련 사이트 관리자2 2014.03.20 56090
공지 본 게시판은 개발자 여러분들의 질문과 답변을 공유하는 공간입니다. 관리자 2012.01.10 99535
274 [질문] 개발자 Q/A에 있는 QR/바코드 스캐너 앱 샘플코드(ZXing, TFrameStand 사용) 설치하여 10.2 Tokyo 모바일에서실행하니 첨부파일같이 오류가 납니다 [5] file delphi 2018.01.11 645
273 seatle에서 android ini 파일 생성? [5] 열심히*^^* 2015.12.04 652
272 unable to start gdbserver on port '64311' can't open socket: permission denied delphi 2019.06.04 655
271 현재 XE8로 지원되는 스마트워치 종류를 알고싶습니다. [1] 가을이다 2015.08.27 663
270 MemoryStream 문의입니다 [2] file 최민철 2015.09.08 663
269 uses permission으로 설정한 권한 런타임시 허용 대화상자 띄우는 방법이 궁금합니다. [1] 김태윤 2018.05.24 676
268 RIO 에서 카메라 사용 Permission 주의할 점 [3] file 지병철 2018.12.12 676
267 [XE8] 안드로이드 default키보드 IME 모드 [2] 가을이다 2015.10.29 677
266 파이어몽키 mms 장문문자+이미지파일및 첨부파일 전송?? [1] kerry 2017.12.07 680
265 폰에 존재하는 call log(즉 수발/발신) 목록 가져오기 [1] 솔루피온 2015.02.16 681
264 특정 번호로 기본SMS 앱을 열려면? [2] 세민 2020.06.03 682
263 안드로이드 백버튼시 선택 가능한 알림창 띄우기 [2] 씨애틀 2016.03.09 682
262 ScrollBox안에 Edit 가상키보드 문제.. [4] 운직 2021.07.14 685
261 IdHttp 대체 NetHTTPClient 관련하여.. [1] 제갈공명 2017.04.11 686
260 ## Windows10 최근 업데이트후 TWebbrowser 심각한 문제.. [2] 가을이다 2015.12.31 694
259 안드로이드 5에서 델파이로 만든 앱이 실행되지 않습니다. [1] 첨처럼 2015.06.17 696
258 TStringList 사용시 인덱스를 찾을수 있나요? [1] 도담 2017.08.17 697
257 PALY스토어 앱 자동 업데이트 file 델파인 2019.03.31 704
256 앱 디플로이 시 디버그 정보를 False로 어떻게 바꿉니까? [2] 푸른솔 2016.10.04 707
255 비콘 감지중 블루투스를 사용자가 강제로 off시 어떻게 처리해야 할까요? 김태윤 2016.07.15 708