unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, StdCtrls, Buttons, Grids, DBGrids; type TForm1 = class(TForm) DBGrid1: TDBGrid; DBGrid2: TDBGrid; SpeedButton1: TSpeedButton; StaticText1: TStaticText; StaticText2: TStaticText; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; ADOConnection1: TADOConnection; R1: TADOTable; R2: TADOTable; DataSource1: TDataSource; DataSource2: TDataSource; Zapros: TADOQuery; R1ID: TIntegerField; R1Obiom: TIntegerField; R1Chisl_pravda: TIntegerField; R1Chisl_spid: TIntegerField; R2Id: TIntegerField; R2Gaz: TWideStringField; R2Chena_prod: TBCDField; R2Chena_zak: TBCDField; R2Chena_vozv: TBCDField; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses Unit2; {$R *.dfm} procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin Form2.Close; end; procedure TForm1.FormShow(Sender: TObject); begin DBGrid1.Columns[0].Width:=43; DBGrid1.Columns[1].Width:=113; DBGrid1.Columns[2].Width:=190; DBGrid1.Columns[3].Width:=207; DBGrid2.Columns[0].Width:=38; DBGrid2.Columns[1].Width:=118; DBGrid2.Columns[2].Width:=89; DBGrid2.Columns[3].Width:=82; DBGrid2.Columns[4].Width:=88; end; procedure TForm1.SpeedButton1Click(Sender: TObject); var i,j:byte; arr:variant; m,n,k,k1,k2:integer; s:string; begin n:=r1.RecordCount; if r2id.AsInteger=1 then s:='Chisl_pravda' else s:='Chisl_spid'; Arr:=VarArrayCreate([1, n, 1, n], varVariant); i:=1;j:=1; Zapros.First; r1.First; For i:=1 to n do begin k:=r1.fieldbyname('Obiom').AsInteger;//закупка Zapros.First; For j:=1 to n do begin k1:=Zapros.fieldbyname('Obiom').AsInteger;//спрос if (k=k1) then arr[i,j]:=k*R2.fieldbyname('Chena_zak').asfloat; if k1=0 then arr[i,j]:=(k*R2.fieldbyname('Chena_vozv').asfloat)- (k*R2.fieldbyname('Chena_zak').asfloat); if k>k1 then arr[i,j]:=((k-k1)*R2.fieldbyname('Chena_vozv').asfloat)+ (k1*R2.fieldbyname('Chena_prod').asfloat)- (k*R2.fieldbyname('Chena_zak').asfloat); if kk1 then begin k1:=k;k2:=i;end; end; Form1.StaticText1.caption:=inttostr(k1); r1.Recno:=k2; Form1.StaticText2.caption:=inttostr(r1obiom.AsInteger); end; end.