home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / source / docs / objectex / ex21.pp < prev    next >
Encoding:
Text File  |  2000-01-01  |  569 b   |  29 lines

  1. Program ex21;
  2.  
  3. { Program to demonstrate the TCollection.Foreach method }
  4.  
  5. Uses Objects,MyObject; { For TMyObject definition and registration }
  6.  
  7. Var C : PCollection;
  8.     M : PMyObject;
  9.     I : Longint;
  10.  
  11. Procedure PrintField (Dummy: Pointer;P : PMyObject);
  12.  
  13. begin
  14.   Writeln ('Field : ',P^.GetField);
  15. end;
  16.     
  17. begin
  18.   C:=New(PCollection,Init(100,10));
  19.   For I:=1 to 100 do
  20.     begin
  21.     M:=New(PMyObject,Init);
  22.     M^.SetField(100-I);
  23.     C^.Insert(M);
  24.     end;
  25.   Writeln ('Inserted ',C^.Count,' objects');
  26.   C^.ForEach(@PrintField);
  27.   C^.FreeAll;
  28.   Dispose(C,Done);
  29. end.