Copy data from pointer?

...
  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: PAnalyzeInfoone that contains data, and I want to copy it into a new independent variable. MyData : TAnalyzeInfo.

Is it possible to copy the whole structure or add it one by one?

+3
source share
3 answers

In Delphi, you can copy a record by simply assigning it, thanks to the magic of the compiler.

MyData := DataSource^;

Dynamic arrays are counted by reference, so the job also serves dynamic arrays if you don't need a real deep copy. With a simple purpose, they just use the same memory.

If you do not want you to be able to copy them individually:

MyData.pPitch = Copy(pDataSource^.pPitch, Low(pDataSource^.pPitch), 
                                          High(pDataSource^.pPitch);
+5
source

, . :

, . .

+4

you can use the move procedure declared in the system unit: system.move (pDataSource ^, MyData, sizeof (TAnalyzeInfo));

+1
source

Source: https://habr.com/ru/post/1772592/


All Articles