Está en la página 1de 2

COMO CREAR UNA MATRIZ CON DELPHI

Bien, haber si es esto lo que buscas:

Inserta un Edit, y dos botones, lo ms arriba del form que puedas, de forma horizontal (uno a la
derecha del otro), luego en uno de los botones agrega esto:

declara estas variables


var i,j,x,y:integer;

luego este codigo, en su evento onClick (con este codigo se crea la estructura de la matriz)

for i:=1 to StrToInt(Edit1.Text) do begin


x:=16;
for j:=1 to StrToInt(Edit1.Text) do begin
if TLabel(FindComponent('Label'+inttostr(i)+inttostr(j)+inttostr(j)))<> nil then
TLabel(FindComponent('Label'+inttostr(i)+inttostr(j)+inttostr(j))).Destroy;

if TEdit(FindComponent('Ed'+inttostr(i)+inttostr(j)+inttostr(j)))<> nil then


TEdit(FindComponent('Ed'+inttostr(i)+inttostr(j)+inttostr(j))).Destroy;
end;
if TLabel(FindComponent('LbI'+inttostr(i)))<> nil then
TLabel(FindComponent('LbI'+inttostr(i))).Destroy;
if TLabel(FindComponent('LbI'+inttostr(i)))<>nil then
TLabel(FindComponent('LbI'+inttostr(i))).Destroy;
if TEdit(FindComponent('EdI'+inttostr(i)))<>nil then
TEdit(FindComponent('EdI'+inttostr(i))).Destroy;
end;

y:=72;
for i:=1 to StrToInt(Edit1.Text) do begin
x:=16;
for j:=1 to StrToInt(Edit1.Text) do begin
TLabel.Create(self).Name:='Label'+inttostr(i)+inttostr(j)+inttostr(j);
with TLabel(FindComponent('Label'+inttostr(i)+inttostr(j)+inttostr(j)))do begin
if j>1 then
Caption:='+ a'+inttostr(i)+inttostr(j)
else
Caption:='a'+inttostr(i)+inttostr(j);
Parent:=Form1;
Left := x;
Top:= y;
end;
TEdit.Create(self).Name:='Ed'+inttostr(i)+inttostr(j)+inttostr(j);
with TEdit(FindComponent('Ed'+inttostr(i)+inttostr(j)+inttostr(j)))do begin
text:='1';
width:=41;
Parent:=Form1;
Left := x+32;
Top:= y-8;
end;
x:=x+80;
end;
TLabel.Create(self).Name:='LbI'+inttostr(i);
with TLabel(FindComponent('LbI'+inttostr(i)))do begin
Caption:=' = b'+inttostr(i);
Parent:=Form1;
Left := x;
Top:= y;
end;
TEdit.Create(self).Name:='EdI'+inttostr(i);
with TEdit(FindComponent('EdI'+inttostr(i)))do begin
text:='';
width:=41;
Parent:=Form1;
Left := x+30;
Top:= y-8;
end;
y:=y+32;
end

Luego en el otro botn, declara estas variables:


var i,j:integer;
suma:real;

Y pon este codigo, en su evento onClick

for i:=1 to StrToInt(Edit1.Text) do begin


suma:=0;
for j:=1 to StrToInt(Edit1.Text) do begin
with TEdit(FindComponent('Ed'+inttostr(i)+inttostr(j)+inttostr(j)))do begin
suma:=suma+(StrToFloat(Text)*j);
end;
TEdit(FindComponent('EdI'+inttostr(i))).Text:=FloatToStr(suma);
end;
end;

Al darle click en el primer botn, se te muestran una serie de edits, para que pongas los valores de
a, cara casa miembro de la matriz, luego al darle click al segundo botn se empieza con las
operaciones, en el primer edit, el que insertas al inicio se pone el valor para darle tamao a la
matriz, puedes poner cualquier numero, teniendo en cuenta que mientras sea ms grande, ms
tardado ser el proceso

También podría gustarte