Dialogs, Menus, ExtCtrls, Buttons, StdCtrls, GraphicDiagram, ExtDlgs,
ComCtrls, ToolWin, ActnList, ImgList;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
Fileitem: TMenuItem;
ItemNew: TMenuItem;
N2: TMenuItem;
SavePicture: TMenuItem;
SaveData: TMenuItem;
N5: TMenuItem;
ItemExit: TMenuItem;
Run: TMenuItem;
StartLoad: TMenuItem;
Pause: TMenuItem;
Face: TMenuItem;
Pilar: TMenuItem;
Lines: TMenuItem;
Options: TMenuItem;
COMport: TMenuItem;
LPTport: TMenuItem;
Generator: TMenuItem;
N19: TMenuItem;
PortOption: TMenuItem;
GeneratorOption: TMenuItem;
Help: TMenuItem;
About: TMenuItem;
UserGuide: TMenuItem;
Panel1: TPanel;
PanelInstrument: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
Timer1: TTimer;
GraphicDiagram1: TGraphicDiagram;
ScrollBar1: TScrollBar;
SavePictureDialog1: TSavePictureDialog;
SaveDialog1: TSaveDialog;
ActionList1: TActionList;
ImageList1: TImageList;
newGraphic: TAction;
saveDataGr: TAction;
LoadDataGR: TAction;
SaveGraph: TAction;
StartGr: TAction;
StopGr: TAction;
HelpPr: TAction;
ExitPr: TAction;
N7: TMenuItem;
SpeedButton7: TSpeedButton;
N8: TMenuItem;
OpenDialog1: TOpenDialog;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
Edit10: TEdit;
Edit11: TEdit;
Edit12: TEdit;
Edit13: TEdit;
Edit14: TEdit;
Edit15: TEdit;
Label1: TLabel;
Edit16: TEdit;
BitBtn1: TBitBtn;
procedure ItemExitClick(Sender: TObject);
procedure Panel1Resize(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure PanelInstrumentResize(Sender: TObject);
procedure ItemNewClick(Sender: TObject);
// procedure SavePictureClick(Sender: TObject);
// procedure SaveDataClick(Sender: TObject);
procedure PauseClick(Sender: TObject);
procedure ClearClick(Sender: TObject);
procedure LinesClick(Sender: TObject);
procedure Start(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SavePictureClick(Sender: TObject);
procedure GeneratorClick(Sender: TObject);
procedure LPTportClick(Sender: TObject);
procedure COMportClick(Sender: TObject);
procedure ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
var ScrollPos: Integer);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure AboutClick(Sender: TObject);
procedure newGraphicExecute(Sender: TObject);
procedure ExitPrExecute(Sender: TObject);
procedure StartGrExecute(Sender: TObject);
procedure StopGrExecute(Sender: TObject);
procedure SaveGraphExecute(Sender: TObject);
procedure saveDataGrExecute(Sender: TObject);
procedure HelpPrExecute(Sender: TObject);
procedure LoadDataGRExecute(Sender: TObject);
procedure ChangeTable(k:integer);
procedure BitBtn1Click(Sender: TObject);
procedure GeneratorOptionClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit3, aboutProgram, Unit4;
{$R *.dfm}
procedure TForm1.ItemExitClick(Sender: TObject);
begin
close;
end;
procedure TForm1.ChangeTable(k:integer);
var t:integer;
begin
t:=GraphicDiagram1.GetPointsCount;
if t<>0 then begin
if t>15 then
begin
Edit1.Text:=Edit2.Text;
Edit2.Text:=Edit3.Text;
Edit3.Text:=Edit4.Text;
Edit4.Text:=Edit5.Text;
Edit5.Text:=Edit6.Text;
Edit6.Text:=Edit7.Text;
Edit7.Text:=Edit8.Text;
Edit8.Text:=Edit9.Text;
Edit9.Text:=Edit10.Text;
Edit10.Text:=Edit11.Text;
Edit11.Text:=Edit12.Text;
Edit12.Text:=Edit13.Text;
Edit13.Text:=Edit14.Text;
Edit14.Text:=Edit15.Text;
Edit15.Text:=IntToStr(k);
end
else begin
case t of
1: Edit1.Text:=IntToStr(GraphicDiagram1.GetValue(0));
2: Edit2.Text:=IntToStr(k);
3: Edit3.Text:=IntToStr(k);
4: Edit4.Text:=IntToStr(k);
5: Edit5.Text:=IntToStr(k);
6: Edit6.Text:=IntToStr(k);
7: Edit7.Text:=IntToStr(k);
8: Edit8.Text:=IntToStr(k);
9: Edit9.Text:=IntToStr(k);
10: Edit10.Text:=IntToStr(k);
11: Edit11.Text:=IntToStr(k);
12: Edit12.Text:=IntToStr(k);
13: Edit13.Text:=IntToStr(k);
14: Edit14.Text:=IntToStr(k);
15: Edit15.Text:=IntToStr(k);
end;
end;
end;
end;
procedure TForm1.Panel1Resize(Sender: TObject);
begin
// panel1.Width:=form1.Width-10;
// panel1.Height:=form1.Height-200;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
GraphicDiagram1.Resize(TControl(panel1));
// panel1Resize(self);
PanelInstrumentResize(self);
end;
procedure TForm1.PanelInstrumentResize(Sender: TObject);
begin
PanelInstrument.Width:=form1.Width-10;
end;
procedure TForm1.ItemNewClick(Sender: TObject);
var n:integer;
begin
GraphicDiagram1.Clear;
ScrollBar1.Enabled:=false;
end;
procedure TForm1.PauseClick(Sender: TObject);
begin
if GraphicDiagram1.GetPointsCount<>1 then
begin
if SpeedButton4.Caption='Запуск' then
begin
Fileitem.Enabled:=false;
// Interpolation.Enabled:=false;
Options.Enabled:=false;
SpeedButton1.Enabled:=false;
SpeedButton2.Enabled:=false;
SpeedButton3.Enabled:=false;
SpeedButton4.Caption:='Зупинити';
StartLoad.Caption:='Зупинити';
Timer1.Interval:=GraphicDiagram1.NumMiliSec;
Timer1.Enabled:=True;
Pause.Enabled:=true;
SpeedButton5.Enabled:=true;
end else
begin
if GraphicDiagram1.GetPointsCount>GraphicDiagram1.DrawCount then
begin
ScrollBar1.Enabled:=true;
ScrollBar1.SetParams(GraphicDiagram1.GetPointsCount,0,GraphicDiagram1.GetPointsCount);
end;
Fileitem.Enabled:=true;
// Interpolation.Enabled:=true;
Options.Enabled:=true;
SpeedButton1.Enabled:=true;
SpeedButton2.Enabled:=true;
SpeedButton3.Enabled:=true;
SpeedButton4.Caption:='Запуск';
StartLoad.Caption:='Запуск';
Timer1.Enabled:=false;
Pause.Enabled:=false;
SpeedButton5.Enabled:=false;
//Stop;
end;
end
else
begin
ScrollBar1.Enabled:=false;
Pause.Enabled:=false;
SpeedButton5.Enabled:=false;
end;
end;
procedure TForm1.ClearClick(Sender: TObject);
begin
form1.ItemNewClick(self);
end;
procedure TForm1.Start;
var
n:TPoint;
begin
new(n);
n^:=Random(255);
GraphicDiagram1.AddValue(n);
ChangeTable(n^);
end;
procedure TForm1.LinesClick(Sender: TObject);
begin
if not(Lines.Checked)then
begin
GraphicDiagram1.TypeDiagram:=tdLine;
Lines.Checked:=true;
Pilar.Checked:=false;
end else
begin
GraphicDiagram1.TypeDiagram:=tdColumn;
Lines.Checked:=false;
Pilar.Checked:=true;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
inherited;
randomize;
Form1.Pause.Enabled:=false;
Form1.SpeedButton5.Enabled:=false;
ScrollBar1.Enabled:=false;
Edit1.Text:='0';
// SaveDialog1.Create(self);
end;
procedure TForm1.SavePictureClick(Sender: TObject);
var
k:integer;
t:String;
begin
if SavePictureDialog1.Execute then
begin
t:=SavePictureDialog1.FileName;
repaint;
k:=GraphicDiagram1.SavePicture(t);
if k=0 then MessageDlg('Помилка при записі файла '+t,mtError,[mbOk],0);
end;
end;
procedure TForm1.GeneratorClick(Sender: TObject);
begin
if not(Generator.Checked) then
begin
Generator.Checked:=true;
COMport.Checked:=false;
LPTport.Checked:=false;
end;
end;
procedure TForm1.LPTportClick(Sender: TObject);
begin
if not(LPTport.Checked)then
begin
Generator.Checked:=false;
COMport.Checked:=false;
LPTport.Checked:=true;
end;
end;
procedure TForm1.COMportClick(Sender: TObject);
begin
if not(COMport.Checked)then
begin
Generator.Checked:=false;
COMport.Checked:=true;
LPTport.Checked:=false;
end;
end;
procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
var ScrollPos: Integer);
begin
if ScrollCode=scEndScroll then
begin
if (ScrollPos<>0) and (ScrollPos<>GraphicDiagram1.GetPointsCount) then
begin
GraphicDiagram1.DrawStart:=ScrollPos-1;
GraphicDiagram1.Invalidate;
end
else if ScrollPos=0 then
begin
GraphicDiagram1.DrawStart:=0;
GraphicDiagram1.Invalidate;
end else
begin
GraphicDiagram1.DrawStart:=ScrollPos-1;
GraphicDiagram1.Invalidate;
end;
end;
end;
procedure TForm1.N2Click(Sender: TObject);
begin
Form3.Showmodal;
end;
procedure TForm1.N3Click(Sender: TObject);
begin
//form2.Show;
end;
procedure TForm1.N4Click(Sender: TObject);
begin
form3.Show;
end;
procedure TForm1.N6Click(Sender: TObject);
begin
// form4.show;
end;
procedure TForm1.AboutClick(Sender: TObject);
begin
aboutbox.showmodal;
end;
procedure TForm1.newGraphicExecute(Sender: TObject);
begin
form1.ItemNewClick(self);
end;
procedure TForm1.ExitPrExecute(Sender: TObject);
begin
close;
end;
procedure TForm1.StartGrExecute(Sender: TObject);
begin
ScrollBar1.Enabled:=false;
Fileitem.Enabled:=false;
// Interpolation.Enabled:=false;
Options.Enabled:=false;
SpeedButton1.Enabled:=false;
SpeedButton2.Enabled:=false;
SpeedButton3.Enabled:=false;
Timer1.Interval:=GraphicDiagram1.NumMiliSec;
Timer1.Enabled:=True;
Pause.Enabled:=true;
SpeedButton5.Enabled:=true;
end;
procedure TForm1.StopGrExecute(Sender: TObject);
begin
if GraphicDiagram1.GetPointsCount>GraphicDiagram1.DrawCount then
begin
ScrollBar1.Enabled:=true;
ScrollBar1.SetParams(GraphicDiagram1.GetPointsCount,0,GraphicDiagram1.GetPointsCount);
end;
Fileitem.Enabled:=true;
// Interpolation.Enabled:=true;
Options.Enabled:=true;
SpeedButton1.Enabled:=true;
SpeedButton2.Enabled:=true;
SpeedButton3.Enabled:=true;
Timer1.Enabled:=false;
Pause.Enabled:=false;
end;
procedure TForm1.SaveGraphExecute(Sender: TObject);
begin
SavePictureClick(Sender);
end;
procedure TForm1.saveDataGrExecute(Sender: TObject);
begin
if SaveDialog1.Execute then
GraphicDiagram1.SaveData(SaveDialog1.FileName);
end;
procedure TForm1.HelpPrExecute(Sender: TObject);
begin
aboutBox.ShowModal;
end;
procedure TForm1.LoadDataGRExecute(Sender: TObject);
begin
if openDialog1.Execute then
begin
if fileExists (openDialog1.FileName) then
GraphicDiagram1.LoadData(openDialog1.FileName)
else messageDlg('Немає такого файлу!!',mtError,[mbOk],0);
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
try
GraphicDiagram1.NumMiliSec:=StrToInt(Edit16.Text);
except MessageDlg('Число повинне бути цілим та додатнім!!!',mtError,[mbOk],0); end
end;
procedure TForm1.GeneratorOptionClick(Sender: TObject);
begin
Form4.showmodal;
end;
end.
Текст компонента GraphicDiagram
unit GraphicDiagram;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
const WM_MYMessage = WM_USER+1000;
const MAX_COUNT = 10000;
type
TTypeDiagram = (tdLine,tdColumn,tdUser);
TPoint = ^Longint;
TPointArray = TList;
TCount = 0..MAX_COUNT;
TnewMouseMoveEvent = procedure (Sender:TObject;Shift:TShiftState;x,y:integer;
var DoDefault:boolean) of Object;
TGraphicDiagram = class(TGraphicControl)
private
FTypeDiagram:TTypeDiagram;
FpointStart:Longint;//початок відображення точок на графіку
FPointDrawCount:Longint; //Кінець відображення точок на графіку
FNumSeccond,FNumMSeccond:word; // кількість мілісекунд, після яких добавляється точка
FPointYMax:Longint; //максимальна точка по Ігрик
FDrawX:Boolean;
FDrawY:Boolean;
FDRAWColor:TColor;
FDrawGridX:Boolean;
FDrawGridY:Boolean;
FDrawGridColor:TColor;
FPointsValue:TPointArray; // тільки додатні елементи
FDataStart,FDataStop:TDateTime;//початок відображення точок на графіку
FEnabled:Boolean;
FOnMouseMove:TnewMouseMoveEvent;
OurTime:longint;
MashtabX:real;
MashtabY:real;
FMashTab:Boolean; //маштаб якщо він змінився то true
// function GetValue(index:Longint): Longint; //читає точку
Procedure SetValue(index,value:Longint); //добавляє точку
procedure SetTypeDiagram(typeD:TTypeDiagram);
procedure SetMashtabX;
procedure SetMashtabY;
protected
procedure paint;override;
procedure WritePoints(stream:TStream);virtual;
procedure ReadPoints(stream:TStream);virtual;
procedure DefineProperties(Filer:TFiler);override;
procedure WMMouseMove(var Mes:TWMMouse); message WM_MOUSEMOVE;
procedure MyMouseMove(Shift:TShiftState;x,y:integer);dynamic;
Procedure WMMyMessage(var Mes:TMessage); message WM_MyMessage;
public
{ Public declarations }
constructor create(AOwner:TComponent);override;
destructor Destroy; override;
procedure AddValue(value:TPoint);overload;
function GetPointsCount:Longint; //читає точку
function getList:TPointArray;
function SaveData(filename:String):integer;
function LoadData(filename:String):integer;
function SavePicture(filename:String):integer;
procedure Start;
procedure Stop;
procedure Clear;
procedure Resize(Sender:TControl);
function GetValue(index:Longint): Longint; //читає точку
// procedure AddValue(value:longint);overload;
published
{ Published declarations }
property TypeDiagram:TTypeDiagram read FTypeDiagram write FTypeDiagram;
property DrawCount:integer read FPointDrawCount Write FPointDrawCount;
property DrawX:Boolean read FDrawX Write FDrawX;
property DrawY:Boolean read FDrawY Write FDrawY;
property DrawGridX:Boolean read FDrawGridX Write FDrawGridX;
property DrawGridY:Boolean read FDrawGridY Write FDrawGridY;
property DrawColor:TColor read FDrawColor Write FDrawColor;
property DrawGridColor:TColor read FDrawGridColor Write FDrawGridColor;
property DrawStart:integer read FPointStart Write FPointStart;
property NumSeccondShow:word read FNumSeccond write FNumSeccond stored false;
property NumMiliSec:word read FNumMSeccond write FNumMSeccond stored false;
property OnMouseMove:TnewMouseMoveEvent read FOnMouseMove write FOnMouseMove;
end;
procedure Register;
implementation
procedure TGraphicDiagram.Resize;
begin
Height:=Sender.Height-30;
Width:=Sender.Width-15;
invalidate;
end;
function TGraphicDiagram.getList:TPointArray;
begin
result:=FPointsValue;
end;
procedure TGraphicDiagram.Start;
begin
FDataStart:=now;
end;
procedure TGraphicDiagram.Stop;
begin
FDataStop:=now;
end;
destructor TGraphicDiagram.destroy;
begin
Self.clear;
inherited;
end;
procedure TGraphicDiagram.Clear;
var l:^Longint;
i:TPoint;
n:Longint;
begin
n:=FPointsValue.Count-1;
FPointsValue.clear;
FpointStart:=0;
new (i);
i^:=0;
AddValue(i);
invalidate;
end;
function TGraphicDiagram.LoadData;
var i:Longint;
n:^Longint;
f:textFile;