[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to transfer from string to byte array

Posted on 2004-10-24
9
Medium Priority
?
7,847 Views
Last Modified: 2010-07-27
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
0
Comment
Question by:abdate
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12393093
Try:

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

or

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

Expert Comment

by:robert_marquardt
ID: 12393176
If the buffer is not changed by the call to the function then a PByte(PChar(m1)) should be good enough.
0
 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 12393770
you might be interested in www.delphibasics.co.uk

lots of info on delphi data types and conversions - essential reading/refereance
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Accepted Solution

by:
esoftbg earned 400 total points
ID: 12394260
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
 
LVL 12

Expert Comment

by:esoftbg
ID: 12394318
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
 

Author Comment

by:abdate
ID: 12395462
Sorry I don't know how to split points to LRHGuy.
Although his answer is good too.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12398666
[kretzschmar],
please split the points to [LRHGuy] and [esoftbg] as [abdate] wants to do it.
Emil
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12431260
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question