I'm having a problem saving a vary large database type in Delphi. It contains an array[1..3500] of TItem, which in turn has two arrays[1..50] and [1..20]. I get a stack overflow unless I set the variable as a Pointer and use the GetMem, FreeMem commands below, but then I can't save it. Code is below.
procedure TDatabase.SaveDB;  
var  
 TempDB: ^TSaveDB;  
 K, X: integer;  
 sComment, sTitle, sComposer, sISDN, sCategory: string;  
begin  
GetMem(TempDB, SizeOf(TSaveDB));  
TempDB.CatCount := fCategoryCount;  
TempDB.ItemCount := fItemCount;  
for K := 1 to fCategoryCount do  
 TempDB.Categories[K] := fCategories[K];  
for K := 1 to fItemCount do  
 begin  
  fItems[K].ReturnSet(sTitle, sComposer, sCategory, sISDN, sComment);  
  with TempDB.Items[K] do  
   begin  
    Title := sTitle;  
    Composer := sComposer;  
    Category := sCategory;  
    ISDN := sISDN;  
   end;  
  TempDB.Items[K].Comments[1] := Copy(sComment, 1, 255);  
   Delete(sComment, 1, 255);  
  TempDB.Items[K].Comments[2] := Copy(sComment, 1, 255);  
   Delete(sComment, 1, 255);  
  TempDB.Items[K].Comments[3] := Copy(sComment, 1, 255);  
   Delete(sComment, 1, 255);  
  TempDB.Items[K].Comments[4] := Copy(sComment, 1, 255);  
   Delete(sComment, 1, 255);  
  TempDB.Items[K].KeyWCount := fItems[K].GetKeyCount;  
  for X := 1 to fItems[K].GetKeyCount do  
   TempDB.Items[K].Keywords[X] := fItems[K].GetKeywords(X);  
 end;
AssignFile(DBSave, fSaveName);  
 Rewrite(DBSave);  
  Write(DBSave, TempDB);  
Closefile(dBSave);  
FreeMem(TempDB, sizeof(TSaveDB));  
end;