Cześć, piszę program który obsługuje 15 czujników temperatury (symulator, czujniki są niepodłączone) . Zrobiłem w Delphi 7 nowy projekt - > aplikacja MDI. Troszkę pozmieniałem i teraz otwiera mi się 15 okienek w StringGrid wyświetla mi się godzina pomiaru i jakaś wartość mierzonej temperatury. Chcę zrobić coś takiego, że w każdym z tych piętnastu okienek jest symulowany pomiar temperatury ale z innego zakresu np: w pierwszym temperatury z zakresu od 2 do 3 stopni C, w drugim od -5 do -6 stopni, w trzecim od -10 do -12 itd. Napisałem procedurę która takie coś mi robi, ale robi to stosując przedział temperaturowy dla wszystkich otwartych okienek, a nie dla jednego.
Proszę o podpowiedź jak to zmienić, poniżej jest kod okienka MainForm i MDIChild:
unit MAIN;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, Menus,
StdCtrls, Dialogs, Buttons, Messages, ExtCtrls, ComCtrls, StdActns,
ActnList, ToolWin, ImgList;
type
TMainForm = class(TForm)
MainMenu1: TMainMenu;
procedure FileNew1Execute(Sender: TObject);
procedure HelpAbout1Execute(Sender: TObject);
procedure FileExit1Execute(Sender: TObject);
private
{ Private declarations }
procedure CreateMDIChild(const Name: string; nr_okna: Integer);
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
uses CHILDWIN, about;
procedure TMainForm.CreateMDIChild(const Name: string; nr_okna: Integer);
var
Child: TMDIChild;
begin
{ create a new MDI child window }
Child := TMDIChild.Create(Application);
Child.Width := 170;
Child.Height := 250;
Child.Caption := Name;
case nr_okna of
0: begin
Child.UstawTmp(5,6);
end;
1: begin
Child.UstawTmp(0,1);
end;
2: begin
Child.UstawTmp(-5,-6);
end;
end;
Child.StringGrid1.Cells[0,0] := 'godzina';
Child.StringGrid1.Cells[1,0] := 'temperatura';
end;
procedure TMainForm.FileNew1Execute(Sender: TObject);
var
nazwa: String;
begin
if MDIChildCount = 0 then
begin
nazwa := 'Drób elementy';
CreateMDIChild('Pomiar z ' + nazwa,0);
end;
if MDIChildCount = 1 then
begin
nazwa := 'Ekspedycja';
CreateMDIChild('Pomiar z ' + nazwa,1);
end;
if MDIChildCount = 2 then
begin
nazwa := 'Magazyn drób';
CreateMDIChild('Pomiar z ' + nazwa,2);
end;
end;
procedure TMainForm.HelpAbout1Execute(Sender: TObject);
begin
AboutBox.ShowModal;
end;
procedure TMainForm.FileExit1Execute(Sender: TObject);
begin
Close;
end;
end.
i kod CHILDWIN
unit CHILDWIN;
interface
uses Windows, Classes, Graphics, Forms, Controls, StdCtrls, Grids, ExtCtrls, SysUtils, Math;
type
TMDIChild = class(TForm)
Memo1: TMemo;
StringGrid1: TStringGrid;
Timer1: TTimer;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Timer1Timer(Sender: TObject);
procedure Temp(temp_od,temp_do,x: Integer);
procedure UstawTmp(x,y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
temp1,temp2: Integer;
implementation
{$R *.dfm}
procedure TMDIChild.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TMDIChild.Temp(temp_od, temp_do, x: Integer);
begin
Randomize;
StringGrid1.Cells[1,x - 1] := IntToStr(RandomRange(temp_od, temp_do)) + ',' + IntToStr(Random(6));
end;
procedure TMDIChild.Timer1Timer(Sender: TObject);
var
x : Integer;
begin
x := StringGrid1.RowCount + 1;
StringGrid1.RowCount := x;
StringGrid1.Cells[0,x - 1] := TimeToStr(time());
Temp(temp1,temp2,x);
end;
procedure TMDIChild.UstawTmp(x, y: Integer);
begin
temp1 := x;
temp2 := y;
end;