How to transfer from string to byte array

Hi,All!

I try to transfer from string to Byte then send to a device, but I don't exactly know how to do it. My previous codeing as followss:

procedure TForm1.Button1Click(Sender: TObject);
var
    mBuffer:array[0..100] of Byte;
    m1:String;
    s1:char;
    i:integer;
begin
  m1:='Hello,World!'
  for i:=0 to lenght(m1) do
  begin
     s1:= copy(m1,i,1);                {Has a exception code here.
                                                  I don't know how to code. It should be some function to
                                                 transfer from string to char}
     mBuffer[i]:=ORD(s1);
  end;
end;

Thanks all.
Abdate
abdateAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
esoftbgConnect With a Mentor Commented:
procedure TForm1.Button1Click(Sender: TObject);
var
  mBuffer:array[0..100] of Byte;
  m1:String;
  i:integer;
begin
  m1:='Hello,World!'
  for i:=1 to lenght(m1) do
  begin
     mBuffer[i]:=ORD(m1[i]);
  end;
end;
0
 
LRHGuyCommented:
Try:

Move(M1[1],MBuffer[0],length(M1));

or

Move(M1[0],MBuffer[0],length(M1)+1);
0
 
robert_marquardtCommented:
If the buffer is not changed by the call to the function then a PByte(PChar(m1)) should be good enough.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
DavidBirch2dotComCommented:
you might be interested in www.delphibasics.co.uk

lots of info on delphi data types and conversions - essential reading/refereance
0
 
esoftbgCommented:
procedure TForm1.Button1Click(Sender: TObject);
var
  mBuffer:array of Byte;
  m1:     string;
  I:      Integer;
  L:      Integer;
begin
  m1 := 'Hello,World!';
  L := Length(m1);
  SetLength(mBuffer, L);
  for I := 0 to L-1 do
  begin
    mBuffer[I]:=ORD(m1[I+1]);
    ListBox1.Items.Add(Char(mBuffer[I]));
  end;
end;
0
 
abdateAuthor Commented:
Sorry I don't know how to split points to LRHGuy.
Although his answer is good too.
0
 
esoftbgCommented:
[kretzschmar],
please split the points to [LRHGuy] and [esoftbg] as [abdate] wants to do it.
Emil
0
 
esoftbgCommented:
i just copy and paste the author's comment:

Comment from abdate
Date: 10/25/2004 12:33AM EEST                                                                                                     Author Comment  

Sorry I don't know how to split points to LRHGuy.
Although his answer is good too

//........
So, his desire it was to split the points, but he did not know how ....
0
All Courses

From novice to tech pro — start learning today.