procedure TForm1.Button1Click(Sender: TObject);
type TByteArray=Array of Byte;
function GetStr:TByteArray;
begin
SetLength(Result,100);
StrPCopy(PChar(@Result[0]),'aaaaaaaaaaa');
end;
var B:TByteArray;
begin
B:=GetStr;
ShowMessage(Pchar(@B[0]));
end;
谢谢俩位了先,第一位的试过不行
我的代码如下
//将字符转换成比特型
Function TShortLetter.StringToByt(sOrder:String):array of Byte;
var
SendData:array of byte;
i:Integer;
iOrderLen:Integer;
begin
iOrderLen:=Length(sOrder);
SetLength(SendData,iOrderLen);
for i:=0 to iOrderLen-1do
SendData:=Ord(sOrder[i+1]);
Result:=SendData;
end;
你有没有仔细看?
type TByteArray=Array of Byte;
Function StringToByt(sOrder:String):TByteArray;
var
i:Integer;
iOrderLen:Integer;
begin
iOrderLen:=Length(sOrder);
SetLength(Result,iOrderLen);
for i:=0 to iOrderLen-1do
Result:=Ord(sOrder[i+1]);
end;
procedure TForm1.Button2Click(Sender: TObject);
var S:String;
B:TByteArray;
begin
S:='aaaaaaaaaa';
B:=StringToByt(S);
ShowMessage(Pchar(@B[0]));
end;