Q&A

  • 비쥬얼스튜디오 소스를 델파이로 바꾸려면 어떻게 해야 하나요?
private string GetCheckSum(string str)
{
string strRet = "";
int intLen = str.Length;
int intTot = 0;
char c1,c2;

//  체크 섬 계산 루틴을 집어 넣는다.
for(int cnt=0 ; cnt<intLen ; cnt++)
{
intTot += (int)str[cnt];
}

intTot = intTot & 0xff; // 하우 1바이트 만을 구한다.

c1 =(char) (((intTot & 0xf0)>>4) + 0x30);
c2 =(char) (((intTot & 0x0f)) + 0x30);

strRet = c1.ToString().Trim() + c2.ToString();

return strRet;
}

위 비쥬얼스튜디오 소스를 델파이로 바꾸려면 어떻게 해야 하나요?
고수님 들 답변 부탁 드립니다

아래와 같이 바꾸었는데 에러가 나네요

function TfmConfigSet1.GetCheckSum(p_Str:String):String;
var
i, v_Tot:Byte;
c1, c2:String;
begin
Result:= '';

v_Tot:= 0;
for i:=1 to length(p_Str) do
    v_Tot:= v_Tot + StrToint(p_Str[i]);

v_Tot:= v_Tot and $ff;

c1:= Pchar((((v_Tot and $f0) ShR 4)+$30));
c2:= Pchar((v_Tot and $0f)+$30 );

Result:= Trim(c1) + (c2);
end;
2  COMMENTS
  • Profile
    이중철 2006.02.07 20:44
    function GetCheckSum(str : string) : string;
    var
      i : integer;
      intTot : integer;
      c1, c2 : byte;
    begin
      intTot := 0;
      for i := 1 to Length(str) do
        intTot := intTot + PByte(@str[i])^;

      intTot  := intTot  and $FF;

      c1 := (((intTot and $f0) shr 4) + $30);
      c2 := (((intTot and $0f)) + $30);
      Result := chr(c1) + chr(c2);
    end;

    제가 아는분(입사동기^^)과 이름이 같네요

    결정직인 실수는  StrToint() 입니다.


  • Profile
    최길남 2006.02.08 00:00
    답변 감사 드립니다.. ^_^