Reputation: 3486
...
PAnalyzeInfo = ^TAnalyzeInfo;
TAnalyzeInfo = record
pPitch: array of Single;
pEnergy: array of Single;
pPitchAccent: array of Single;
pEnergyAccent: array of Single;
pDicAccent: array of Single;
pScore: array of Single;
pBoundary: Integer;
szRecWord: array of array of AnsiChar;
nRecWordNum: Integer;
nFrameNum: Integer;
end;
...
I have pDataSource: PAnalyzeInfo
which contains data and I want to copy it to a new independent variable. MyData : TAnalyzeInfo
.
Is it possible to copy the whole structure or adding it one bye one?
Upvotes: 3
Views: 4484
Reputation: 72524
In Delphi you can copy a record just by assigning it, thanks to compiler magic.
MyData := DataSource^;
The dynamic arrays are reference counted, so the assignment also takes care of the dynamic arrays as long as you don't need a real deep copy. With a simple assignment they just share the same memory.
If you don't want that you can copy them individually:
MyData.pPitch = Copy(pDataSource^.pPitch, Low(pDataSource^.pPitch),
High(pDataSource^.pPitch);
Upvotes: 5
Reputation: 11252
No, the dynamic arrays cannot be copied with a single copy command. You will have to:
It would be much easier if the arrays were static. In that case copying the whole memory block would be possible.
Upvotes: 4
Reputation: 287
you can use move procedure declared in the system unit : system.move(pDataSource^, MyData, sizeof(TAnalyzeInfo));
Upvotes: 1