Hello!

I have a little project of my own to convert a memory game puzzle from VB.Net into Delphi (Not a big Delphi fan). I was doing fine so far until a control would not be recognized (outlined in red and green). It is an imagelist containing 8 images.

  1. Why is the control not being recognized?
  2. How would I reference and image from the imagelist?
  3. Can an array have a property (Outlined in green)?

I am using Lazarus Delphi/Pascal?


CODE

unit Unit1; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ExtCtrls, DbCtrls, RTTICtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Image1: TImage;
    Image10: TImage;
    Image11: TImage;
    Image12: TImage;
    Image13: TImage;
    Image14: TImage;
    Image15: TImage;
    Image16: TImage;
    Image17: TImage;
    Image18: TImage;
    Image19: TImage;
    Image2: TImage;
    Image20: TImage;
    Image21: TImage;
    Image22: TImage;
    Image23: TImage;
    Image24: TImage;
    Image25: TImage;
    Image26: TImage;
    Image27: TImage;
    Image28: TImage;
    Image29: TImage;
    Image3: TImage;
    Image30: TImage;
    Image31: TImage;
    Image32: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Image8: TImage;
    Image9: TImage;
    pictures: TImageList;
  private
    { private declarations }
  public
    { public declarations }
  end; 
{====================GLOBAL VARIABLES============================}

{Picturebox Layout}
var
  Form1: TForm1;
  left0: integer ;
  top0 : integer ;
  gap  : integer ;

{Variables}
  TYPE  Coordinates = RECORD
                            Row : Integer ;
                            Col : Integer;
                            (* etc *)
                       END;


  var
  picarray : array[1..4,1..4] of timage;
  thiscover, lastcover : timage    ;
  imageindex : array[1..4,1..4] of integer;
  picloc : array[1..2] of coordinates     ;
    clickcount, pairsfound, attemptcount : integer;



{================= END GLOBAL VARIABLES========================}

implementation


procedure start;
  var i, j : integer;
  whichrow, whichcol : integer;
  begin


  for i := 0 to 3  do
  begin
  for j := 0 to 3     do
  begin
  imageindex[i,j] := -1  ;
  end
  end        ;
     randomize;
  for i := 0 to 7  do
  begin
  for j := 1 to 2 do
  begin
  whichcol := random(4)  ;
  whichrow := random(4)   ;
  end
  end       ;
  repeat
  picarray[whichcol, whichrow].picture := pictures.getbitmap(imageindex, picarray) ;
  imageindex[whichcol, whichrow] = (i)  ;
  until imageindex[whichcol,whichrow] = -1;

            end;



initialization
  {$I unit1.lrs}







end.

COMPILER ERROR

Hint: Start of reading config file c:\lazarus\fpc\2.2.4\bin\i386-win32\fpc.cfg
Hint: End of reading config file c:\lazarus\fpc\2.2.4\bin\i386-win32\fpc.cfg
Free Pascal Compiler version 2.2.4 [2009/10/25] for i386
Copyright (c) 1993-2008 by Florian Klaempfl
Target OS: Win32 for i386
Compiling project1.lpr
Compiling unit1.pas
unit1.pas(108,50) Error: Identifier not found "pictures"

unit1.pas(109,41) Error: Illegal expression
unit1.pas(127) Fatal: There were 4 errors compiling module, stopping

Thanks for any help. It is the memory game where you pick 2 cards from a grid of cards to match them.

And yes, the imagelist is called 'pictures' (thats what the (name) property has in it anyway)

Examine carefully classes. You invented the wheel.
Note the two properties have TForm1 - Controls [], and Components []. Number of them ControlsCount and ComponentsCount.
You put in design time 32 TImage component on TForm1. Hence Form1 already contains an array of pointers. Likewise, instead of TForm could be such TPanel.
See your TImage can be as follows:
for i: = 0 to Form1.ComponentsCount-1 do
if (Form1.Component isTImage) then
(Form1.Component as TImage). Picture.Assign (...);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.