今天群裡有人問函式使用問題,我就自己測試一下,順便學習一下。
uses math; procedure TForm2.Button1Click(Sender: TObject); type TTArrayByte= array of Byte; var FSource: PAnsiChar; FArrayByte:TTArrayByte; FSourceLenth: Integer; HexStr: string; begin FSource := '123'; FSourceLenth := Length(FSource);////string=PChar=PWideChar 單個漢字取出長度為1 SetLength(FArrayByte, FSourceLenth); //CopyMemory(@FArrayByte[0], FSource, FSourceLenth); //Move(FSource,FArrayByte[0],Min(FSourceLenth,8)); FArrayByte[0]:=99; Move(FSource[1],FArrayByte[1],Min(FSourceLenth,2)); HexStr := ''; for FSourceLenth := 0 to FSourceLenth do begin HexStr := HexStr + inttoHex(FArrayByte[FSourceLenth], 2); end; ShowMessage(HexStr); ShowMessage(PAnsiChar(FArrayByte)); end;
CopyMemory(陣列值地址,陣列值地址,長度)