Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Otchyot_praktika_1.docx
Скачиваний:
0
Добавлен:
01.04.2025
Размер:
750.49 Кб
Скачать

Interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, Globals, THardwareDef, TStoreDef, ExtCtrls, CommonGraphics;

type

TfrmPlot = class(TForm)

imgPlot: TImage;

procedure FormShow(Sender: TObject);

private

XLevel, YLevel: integer;

XScaleFactor, XScaleQuantity, XScaleLength: integer;

YScaleFactor, YScaleQuantity, YScaleLength: integer;

procedure DrawPlot;

public

{ Public declarations }

end;

var

frmPlot: TfrmPlot;

implementation

{$R *.dfm}

procedure TfrmPlot.DrawPlot;

var

i, mem, maxind, x, y, xprev, ymaxprev, yminprev: integer;

maxprice, minprice: real;

begin

i := 0;

xprev := 0;

ymaxprev := 0;

yminprev := 0;

maxind := dbase.GetMaxIndex;

while (i<=maxind) do

begin

mem := dbase.GetElement(i).Memory;

minprice := dbase.GetElement(i).Price;

while (i<maxind)and(dbase.GetElement(i).Memory = mem) do

inc(i);

if not (dbase.GetElement(i).Memory = mem) then dec(i);

maxprice := dbase.GetElement(i).Price;

inc(i);

with imgPlot.Canvas do

begin

x := YLevel + (mem div XScaleFactor)*XScaleLength;

y := XLevel - Round(maxprice/YScaleFactor)*YScaleLength;

TextOut(x, XLevel + 20, IntToStr(mem));

TextOut(YLevel - 50, y, FloatToStr(maxprice));

MoveTo(YLevel, y);

Pen.Style := psDashDot;

LineTo(x, y);

LineTo(x, XLevel);

Pen.Style := psSolid;

Brush.Color := clRed;

Rectangle(x + 3, y + 3, x - 3, y - 3);

if not(xprev = 0) then

begin

Pen.Style := psDash;

Pen.Color := clRed;

MoveTo(x,y);

LineTo(xprev, ymaxprev);

Pen.Color := clBlack;

Pen.Style := psSolid;

end;

Brush.Color := clWhite;

ymaxprev := y;

y := XLevel - Round(minprice/YScaleFactor)*YScaleLength;

TextOut(YLevel - 50, y, FloatToStr(minprice));

MoveTo(YLevel, y);

Pen.Style := psDashDot;

LineTo(x, y);

LineTo(x, XLevel);

Pen.Style := psSolid;

Brush.Color := clGreen;

Rectangle(x + 3, y + 3, x - 3, y - 3);

if not (xprev = 0) then

begin

Pen.Style := psDash;

MoveTo(x, y);

LineTo(xprev, yminprev);

Pen.Style := psSolid;

end;

xprev := x;

yminprev := y;

Brush.Color := clWhite;

end;

end;

end;

procedure TfrmPlot.FormShow(Sender: TObject);

var

MaxMem: integer;

MaxPrice: real;

begin

imgPlot.Refresh;

XLevel := imgPlot.Height - 40;

YLevel := 60;

MaxMem := dbase.GetMaxMemory;

MaxPrice := dbase.GetMaxPrice;

XScaleFactor := 1024;

XScaleQuantity := Round(MaxMem/XScaleFactor) + 2;

if XScaleQuantity < 6 then XScaleQuantity := 6;

XScaleLength := Round((imgPlot.Width - YLevel - 40)/XScaleQuantity);

YScaleFactor := 1000;

YScaleQuantity := Round(MaxPrice/YScaleFactor) + 2;

if YScaleQuantity < 30 then YScaleQuantity := 30;

YScaleLength := Round((imgPlot.Height - 10)/YScaleQuantity);

DrawGrid(imgPlot, XLevel, YLevel, XScaleFactor, XScaleQuantity,

XScaleLength, YScaleFactor, YScaleQuantity, YScaleLength);

DrawPlot;

end;

end.

unit MainForm;

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]