Array of Pointers -- Assignment lazarus / 62-General ---------------------------------------------------------------------- abtaylr · 2019-10-07 15:29 I am having a difficult time making an assignment to an array of pointers. Here is the code at issue: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  PGrid = ^TStringGrid;   TPix = array of PGrid;   TPixArr = Class(TStringGrid)  private   public    Pix : TPix;    procedure Add(idx : integer);    function Count : integer;   end; ....procedure TPixArr.Add(idx : integer);var  PG : TStringGrid;  PPG : PGrid;begin  PG := TStringGrid.Create(nil);  PG.ColCount := 10;  PG.RowCount := 45;  PPG := @PG;  Pix[idx] := PPG; // <======end; The PGrid is set up in the type area, then in TPixArray.Add(idx) I create a StringGrid PG and set PPG to take an assignment of its address. The next line is the problem. In the array at the index number, I try to assign the pointer, but I get an error every time. I have also tried the routine from the Free Pascal Reference Guide, Types, p.46, where you can use a constructor for an array, but that failed also. I don't see what I am doing wrong and the error message merely refers to the line number without anything else. ---------------------------------------------------------------------- Thaddy · 2019-10-07 15:54 I don't thing you mean a TStringGrid (which is a visual component). but rather a two dimensional array of string? Or a TStringLIST? Anyway your code is completely wrong, but plz explain what you want exactly.... You give me almost nothing to work with... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Type  TColumns = 0..9;   TRows  = TColumns;  // a square matrix of 10 x 10 var  Stringmatrix: array[TColumns,TRows] of string; procedure  AddMatrix(const Col:TColumns; const Row:TRows; const S:String;);begin  StringMatrix[Col,Row] :=S;end; begin   StringMatrix[0,0] := 'test';   // or   AddMatrix(0,1,'Test2');   writeln(StringMatrix[0,0]);   writeln(StringMatrix[0,1]); // etc...end.  Something like that? ---------------------------------------------------------------------- howardpc · 2019-10-07 16:11 Why do you need a pointer to a TStringGrid? Classes are already pointers. Perhaps you want something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   TPix = array of TStringGrid;   TPixArr = class(TComponent)  public    Pix : TPix;    procedure Add(idx: Integer);    constructor Create(AOwner: TComponent); override;  end; implementation procedure TPixArr.Add(idx: integer);begin  if (idx >-1) and (idx < High(Pix)) and not Assigned (Pix[idx]) then    begin      Pix[idx] := TStringGrid.Create(Self);    Pix[idx].ColCount := 10;      pix[idx].RowCount := 45;    end;end;             ... ---------------------------------------------------------------------- Thaddy · 2019-10-07 16:14 Quote from: howardpc on October 07, 2019, 06:11:44 pmWhy do you need a pointer to a TStringGrid? Classes are already pointers. That's why I did not understand it...This is a beginner...  Both options are different interpretations of what he means. ---------------------------------------------------------------------- abtaylr · 2019-10-07 16:59 I started out with a simple array Pixl : an array[0..9,0..44]; and Pix : an array of an array of Pixl. I have gone through many iterations including making Pix an array of TStringGrid. I haven't tried using TColumns and TRows.  The first example is very close to my first try using a TStringGrid, but I got errors trying to use Pix[idx] := TStringGrid.Create(nil). This is the reason that I finally went to PGrid = ^TStringGrid.  An array of pointers, even though a class is also just a pointer, seemed to work, partially. The code I use in later parts of the application de- referencing the pointers all appear to work. It's just the initial setup that goes awry. The reason why I use TStringGrid is because I like using the methods of TStringGrid. This all is going into a form not shown here. On that form I have a string grid showing typical rows and columns, but each column also needs to refer an array of Pixels of 10 X 45. I probably would get to the same end as TStringGrid using the TColumns and TRows. Most of my experience is in C for many years and then Visual Basic in later years on SQL application programming, however, I am very green on Pascal. The closest reference I can make is a relational database tied together with an index, one table drawing a column of single values and another a grid of values. Maybe I should go back to what I know and try to use TDBGrid, but I think I would end up with the same problem. ---------------------------------------------------------------------- abtaylr · 2019-10-07 20:43 Thank you for your assistance! I finally got my code working using a variant of the HowardPC code. Comments from both of you were helpful.