home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 February / DPPCPRO0299.ISO / February / Delphi / Runimage / DELPHI20 / DEMOS / DOC / VARARRAY / MAIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-10  |  1.6 KB  |  76 lines

  1. unit Main;
  2.  
  3. { This program provides very simple examples of using Variant Arrays. Variant
  4.   Arrays are Delphi's version of the Safe Arrays used in standard OLE
  5.   programming.
  6.  
  7.   The code shown here provides examples of using both one dimensional and two
  8.   dimensional variant arrays }
  9.  
  10. interface
  11.  
  12. uses
  13.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  14.   StdCtrls;
  15.  
  16. type
  17.   TVariantArrayForm = class(TForm)
  18.     bOneDim: TButton;
  19.     bTwoDim: TButton;
  20.     procedure bOneDimClick(Sender: TObject);
  21.     procedure bTwoDimClick(Sender: TObject);
  22.   end;
  23.  
  24. var
  25.   VariantArrayForm: TVariantArrayForm;
  26.  
  27. implementation
  28.  
  29. {$R *.DFM}
  30.  
  31. { Simple example showing how to use a one dimensional variant array }
  32.  
  33. procedure TVariantArrayForm.bOneDimClick(Sender: TObject);
  34. var
  35.   MyVariant: Variant;
  36.   S: string;
  37.   I: Integer;
  38. begin
  39.   S := '';
  40.   MyVariant := VarArrayCreate([0, 5], varVariant);
  41.   for I := 0 to 5 do
  42.     MyVariant[I] := I * 2;
  43.   for I := 0 to 5 do
  44.     S := S + ' ' + IntToStr(MyVariant[I]);
  45.  
  46.   ShowMessage(S);
  47. end;
  48.  
  49. { Simple example showing how to use a two dimensional variant array }
  50.  
  51. procedure TVariantArrayForm.bTwoDimClick(Sender: TObject);
  52. var
  53.   MyVariant: Variant;
  54.   I, J: Integer;
  55.   S: string;
  56. begin
  57.   S := '';
  58.  
  59.   MyVariant := VarArrayCreate([0, 5, 0, 5], varInteger);
  60.  
  61.   for I := 0 to 5 do
  62.     for J := 0 to 5 do
  63.       MyVariant[I, J] := I * J;
  64.  
  65.   for I := 0 to 5 do
  66.   begin
  67.     for J := 0 to 5 do
  68.       S := S + IntToStr(MyVariant[I, J]) + ' ';
  69.     S := S + #13;
  70.   end;
  71.  
  72.   ShowMessage(S);
  73. end;
  74.  
  75. end.
  76.