Ok. I still do not see the problem.
I was explaining why I don't need any property called "name", I haven't understood what you said, I'm sorry.
So? everyone has already pointed you to the common data structures you can use lists to dynamic arrays eg
I'm kinda learning by myself (while I'm doing something to be more precise), and I don't have access or money to learn it on a school, so I don't know how to use them (by myself).
I'll try learn the basics a little bit more. so But now I don't have that much knowledge to do all the stuff, my brain also does't help to much with programming.
Erm ok. You already have that with your ArrayExample method. Just pass which ever array you want as the second parameter. I guess I do not see the problem again.
I've tryied to use this kind of structure to create the buttons dinamically, but the results are not stored inside of the "global array", not sure what or how I did it, but the results stay on the "procedure array" because I can't get the global array name / reference (or something like it), will be easier to understand (at least I supose so) with the example.
And the code you showed so far does not work ? Any error messages so we can understand where you are stuck?
I writed it in the browser just to ilustrate my exampleand "there is" no error because it's not a Lazarus or a compiler problem, it's a desing issue (the fact I don't know how to do this piece of code), maybe because I'm using a procedure instead of a function and I'm not returning the result to the rigth place or something like it, sorry once more.
The following code illustrate my "button-array problem", it create the buttons, but not inside of the global arrays, they stay empty even when being used like a reference, thats why I'm trying to get some kind of property or way to return the results to them, the onclose sigseverror and the N5 error stay like a mistery to me.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
type
arrayButtons = Array of TButton;
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
M: TPanel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
{ CUSTOM PROCEDURES }
arrayMain,
arrayPreview,
arrayView : arrayButtons;
l: Integer;
procedure btnFontStyles(btn: TButton; boldArray: arrayButtons);
procedure clickMask(Sender:TObject);
procedure createButtons(arrayName:arrayButtons);
end;
var
Form1 : TForm1;
M : TPanel;
i : Integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
i, t:Integer;
begin
l:=0;
SetLength(arrayMain,5);
createButtons(arrayMain);
//ShowMessage(IntToStr(Length(arrayMain)));
SetLength(arrayPreview,5);
createButtons(arrayPreview);
//ShowMessage(IntToStr(Length(arrayPreview)));
SetLength(arrayView,5);
createButtons(arrayView);
//ShowMessage(IntToStr(Length(arrayView)));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:= Label1.Caption+'Main[0]: ' +arrayMain[0].Name+LineEnding;
Label1.Caption:= Label1.Caption+'Preview[0]: ' +arrayPreview[0].Name+LineEnding;
Label1.Caption:= Label1.Caption+'View[0]: ' +arrayView[0].Name+LineEnding;
end;
procedure TForm1.btnFontStyles(btn: TButton; boldArray: arrayButtons);
var
a, c:Integer;
b:TButton;
begin
for c:=0 to High(boldArray) do begin
arrayMain[i].Font.Style:=[];
a:=a+1;
end;
btn.Font.Style:=[fsBold, fsItalic];
end;
procedure TForm1.createButtons(arrayName: arrayButtons);
var
t, c :Integer;
b :TButton;
begin
t:=0;
SetLength(arrayName, 5);
for c:=0 to High(arrayName) do begin
arrayName[i]:= TButton.Create(Self);
with arrayName[i] do begin
//N should be the array name or some identifier to it, like "arrayMain1" instead of "N1"
Name:='N'+IntToStr(i);
Caption:=arrayName[i].Name;
Width:=100;
Height:=50;
Top:=t;
Left:=l;
Parent:=M;
t:=t+50;
i:=i+1;
OnClick:=@clickMask;
Label1.Caption:=Label1.Caption+'local array: '+Name+LineEnding;
end;
end;
CleanupInstance;
l:=l+110;
//Label1.Caption:=Label1.Caption+'arrayMain: '+arrayMain[0].Name+LineEnding;
end;
procedure TForm1.clickMask(Sender: TObject);
var
button:TButton;
begin
button:=Sender as TButton;
{If I can, somehow put the arrayname on the above function, I'll be able to put it hier and control the selection of the array to play with its elements}
btnFontStyles(button, arrayMain);
end;
end.
I'm sorry for my delay and for my last post, you gave me a pretty good idea, work with a multidimensional array, so I can create the three "columns" to be the three different arrays that I have now and them create the button in the "lines" of each one (at least I compare a "2d" array with a table), in this way I can reference to the "collumn" instead of a array "name", that's a nice one.
Has I said, I'm sorry, I don't get the whole picture when I first read it, like I always avoid arrays I completely forgot it.
Any explanation of the above code and I can set the values to the 2d array will be great, thanks .