Me parece que un ListBox no es el componente más adecuado para mostrar una matríz, un StringGrid es más apropiado, es más,
hace innecesaria la declaración del arreglo bidimensional 'datos'.
El código que te adjunto conserva el array por si lo exige el ejercicio. No hace ninguna comprobación en las conversiones.
Código Delphi
[-]
...
const
MESES = 3;
SUCURSALES = 4;
var
Form1: TForm1;
datos: array[1..MESES,1..SUCURSALES] of Double;
fil: Integer=1;
col: Integer=1;
implementation
procedure TForm1.FormShow(Sender: TObject);
var
i: Integer;
begin
StringGrid1.FixedCols:= 1;
StringGrid1.FixedRows:= 1;
StringGrid1.ColCount:= SUCURSALES + 2;
StringGrid1.RowCount:= MESES + 2;
for i:= 1 to MESES do
StringGrid1.Cells[0,i]:= 'Mes '+FloatToStr(i);
StringGrid1.Cells[0,MESES+1]:= 'Tot mes';
for i:= 1 to SUCURSALES do
StringGrid1.Cells[i,0]:= 'Suc '+FloatToStr(i);
StringGrid1.Cells[SUCURSALES+1,0]:= 'Tot suc';
end;
procedure TForm1.CalcularTotales;
var
i,j: Integer;
t: Double;
begin
for i:= 1 to MESES do
begin
t:= 0;
for j:= 1 to SUCURSALES do
t:= t + datos[i,j];
StringGrid1.Cells[SUCURSALES+1,i]:= FloatToStr(t);
end;
for i:= 1 to SUCURSALES do
begin
t:= 0;
for j:= 1 to MESES do
t:= t + datos[j,i];
StringGrid1.Cells[i,MESES+1]:= FloatToStr(t);
end;
end;
procedure TForm1.InsertaClick(Sender: TObject);
begin
if col > SUCURSALES then
begin
CalcularTotales;
showmessage('Ingreso completado');
end
else
begin
datos[fil,col]:= StrToFloat(Edit1.Text);
StringGrid1.Cells[col,fil]:= Edit1.Text;
if (fil = MESES) then
begin
fil:= 0;
Inc(Col);
end;
Inc(fil);
end;
end;
...
Un saludo.