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

  1. Program ex24;
  2.  
  3. { Program to demonstrate the TCollection.IndexOf method }
  4.  
  5. Uses Objects,MyObject; { For TMyObject definition and registration }
  6.  
  7. Var C : PCollection;
  8.     M,Keep : PMyObject;
  9.     I : Longint;
  10.  
  11. begin
  12.   Randomize;
  13.   C:=New(PCollection,Init(100,10));
  14.   Keep:=Nil;
  15.   For I:=1 to 100 do
  16.     begin
  17.     M:=New(PMyObject,Init);
  18.     M^.SetField(I-1);
  19.     If Random<0.1 then
  20.      Keep:=M;
  21.     C^.Insert(M);
  22.     end;
  23.   If Keep=Nil then 
  24.     begin
  25.     Writeln ('Please run again. No object selected');
  26.     Halt(1);
  27.     end;
  28.   Writeln ('Selected object has field : ',Keep^.GetField);
  29.   Write ('Selected object has index : ',C^.IndexOf(Keep));
  30.   Writeln (' should match it''s field.');
  31.   C^.FreeAll;
  32.   Dispose(C,Done);
  33. end.