Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-02

TStringGrid and array

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Kamen Ketev

Hi,
I have a table in Excel with several rows and columns I want to transfer to Lazarus. I put in the form sgW: TStringGrid; when I am clicking on column 1 must be calculated in column 2. But why add the values ??of the last two rows of the second column in the first 2 rows of the 3rd? How can I do this calculations like in Excel? Here's sample code (PosW is var in the original program, here is an example constant):

unit Unit1;
{$mode objfpc}{$H+}
interface
uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids;
type
  { TForm1 }
  TForm1 = class(TForm)
    sgW: TStringGrid;
    procedure sgWClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.lfm}

{ TForm1 }

procedure TForm1.sgWClick(Sender: TObject);
const
  PosW: array[1..12] of double = (90.2943201302, 72.4248719439,68.8869342366,
  45.2598466854,45.2598459837, 326.9552580449,165.9727037213,
  356.5835481932,326.3341381295, 272.031738496, 325.9835619548,211.4549241651);
var
  W: array[-1..12,-1..7] of double;
  i,j: integer;
  StrTest: string;
begin
  // Clear array
  for i := 1 to 12 do
   for j := 1 to 7 do Begin
     W[j,i] := 0.0;
     Str(W[j,i]:3:9,  StrTest);
     sgW.Cells[j,i] := StrTest;
   End;
  for i := 1 to 11 do Begin
    W[1,i] := PosW[i];
    W[2,i] := PosW[i] - PosW[12];
  End;
  for i := 1 to 12 do
   for j := 1 to 7 do Begin
     Str(W[j,i]:3:9,  StrTest);
     sgW.Cells[j,i] := StrTest;
   End;
end;

end.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130206/ed770212/attachment.html>

Reply by email

Jürgen Hestermann
to Kamen Ketev
Kamen Ketev wrote
sgW.Cells[j,i] := StrTest;

Be aware that within sgW.Cells columns and rows start with index 0 and end with last_index-1. So the index number has to be one less than your selfdeclared arrays.

Reply by email

Kamen Ketev

In index 0 I have static values in program. Problem is that its enter values in columns that are not used now. And don't calculate values for rows 10 and 11. Please run the demo.

-------- ?????????? ????? --------
??: J?rgen Hestermann
???????: Re: [Lazarus] TStringGrid and array
??: Lazarus mailing list
????????? ??: ?????, 2013, ???????? 6 19:07:19 EET

Kamen Ketev wrote 7 lines
sgW.Cells[j,i] := StrTest;

Be aware that within sgW.Cells columns and rows start with index 0 and end with last_index-1.

So the index number has to be one less than your selfdeclared arrays.

Reply by email