자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 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 15768
공지 유용한 관련 사이트 관리자2 2014.03.20 54582
공지 본 게시판은 개발자 여러분들의 질문과 답변을 공유하는 공간입니다. 관리자 2012.01.10 97993
2179 화면입력변수를 sql문에 적용하는 방법이 궁금합니다. [2] prince 2016.03.04 239
2178 child form 에서 mdi form 의 버튼 클릭 이벤트 [1] 가나다 2021.03.12 239
2177 Getit 에서 제공되던 Winsoft의 컴포넌트 들이 안보입니다. sihwan 2021.07.15 239
2176 [질문] 안드로이드몬의 효과음 실행은요? [1] 화현 2016.12.27 240
2175 도쿄로 빌드된 앱을 최소화했다가, 기존 실행되었던 앱을 클릭하면 글자의 배경색이 없어집니다. [4] file 델사냥 2017.05.25 240
2174 CTI 연동할때 모니터 하단에서 알림창 같이 떠오르게 하는 방법? 미스터리 2018.08.31 240
2173 RADStudio 10.3 EMS Server 프로덕션 환경 [2] 개성산전 2019.01.09 240
2172 안드로이드 이미지 공유시 문제 [1] 델마당쇠 2019.12.16 240
2171 PrintDialog 관련 문의 [2] 쿤이 2020.03.12 240
2170 Apps must follow the iOS Data Storage Guidelines or they will be rejected silkroad99 2016.01.20 240
2169 FMX StringGrid 다중 선택 어떤식으로 해야할까요? 로로봉 2015.11.17 240
2168 마이그레이션중 LoadLibrary 문제 확인부탁드립니다. file 최진현 2018.06.05 241
2167 오류관련 문의 드립니다 [1] 투덜이스머프투 2019.05.20 241
2166 Access violation 'vcl270.bpl"에러가 발생 합니다. file 하루 2021.03.22 241
2165 재문의-data snap utf8 관련 오류 [3] file 사랑남 2015.08.29 242
2164 "Build All Projects"로 컴파일시 정상동작하지만 "F9"로 컴파일시 에러가 발생합니다. file lamp 2016.09.26 242
2163 Listview ScrollviewPos 위치 변경 버그인가요? silkroad99 2016.11.29 242
2162 object lock not owned. 오류가 나는 원인이 뭔가요?? sihwan 2018.08.03 242
2161 FMX Component 생성시 오류 [2] file 100jk 2018.09.04 242
2160 실행이 너~무 느립니다. [1] 포세가이 2020.02.27 242