Title: Message
what about a TCollection?
 
Jeremy
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ross Levis
Sent: Wednesday, 26 May 2004 22:16
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] dynamic array items

Or perhaps I should byte the bullet and use a TList instead of an array.  It's just that it's a well established program but someone now wants this data sorted when it wasn't originally considered necessary.
 
Cheers,
Ross.
----- Original Message -----
Sent: Wednesday, May 26, 2004 9:27 PM
Subject: RE: [DUG] dynamic array items

A dynamic array is like any other array in it's memory structure for it's element data.
 
You could however have two arrays with the second array being an array of pointers/indexes to the first array elements.
 
If you increase the length of a dynamic array, then it copies the whole array.
 
Myles.
-----Original Message-----
From: Ross Levis [mailto:[EMAIL PROTECTED]
Sent: Wednesday, 26 May 2004 21:24
To: NZ Borland Developers Group - Delphi List
Subject: [DUG] dynamic array items

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

Reply via email to