|
A quick question (I think). Does each item of
a dynamic array use sequential memory space or can each item be in a
completely different memory location? The reason I ask is I want to sort
an array of records (don't ask) and the quickest way would be to
swap pointer locations for each item, rather than move record values
themselves.
As I see it, it depends on whether SetLength moves the whole array to
another memory location as I believe it does with a dynamic
string. I am trying to use a TStringList to do the
sorting and store the address of each array element in the Objects
property, but either it can't be done or I'm doing something wrong because the
records are ending up blank.
Files is an array of FileRec (a record
structure). PFileRec = ^FileRec;
var
FileCnt: Cardinal; FileList: TStringList; FileRecord: PFileRec; begin FileList := TStringList.Create; for FileCnt := 0 to High(Files) do FileList.AddObject(ExtractFilename(Files[FileCnt].Filename),@Files[FileCnt]); FileList.Sort; for FileCnt := 0 to High(Files) do begin FileRecord := Pointer(FileList.Objects[FileCnt]); Files[FileCnt] := FileRecord^; end; FileList.Free; end;
Cheers,
Ross Levis. |
_______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
