?
Solved

CopyMemory() with TObject

Posted on 2005-03-22
2
Medium Priority
?
1,661 Views
Last Modified: 2012-08-14
Hi,

I have a problem copying data from an array to a TObject.  The following is an extract of the code.


type THeader = class(TObject)
  Data: array[1..18] of byte;
end;
..
..

procedure TForm1.ButtonClick(Sender: TObject);
var
  Head: array[1..18] of byte;
  i: integer;
  Header: THeader;
  str1: string;
  str2: string;
begin
  Header := THeader.Create;
 
  for i:=1 to 18 do
    Head[i] := i+1;
 
 //** Problem with this??
  CopyMemory(Header, @Head, SizeOf(Head));

  for i:=1 to 18 do
    begin
      Str1 := Str1 + ' ' + intToStr(Header.Data[i]);
      Str2 := Str2 + ' ' + IntToStr(Head[i]);
    end;

    Showmessage(str1 + ' : ' + str2);
end;

The data in Head is:2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

But when I copy it to the Header Object, the data is: 6 7 8 9 10 11 12 13 14 15 16 17 18 19 0 0 0 0.

How can I fix this so Header is the same as the Head?

TIA.
0
Comment
Question by:engdmorr
[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
2 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 200 total points
ID: 13600891
Hi,

CopyMemory(@(Header.Data), @Head, SizeOf(Head));

Regards, Geo
0
 

Author Comment

by:engdmorr
ID: 13600966
Works a treat, thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 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