Программная реализация разложения временного процесса в тригонометрический ряд

Курсовой проект - Компьютеры, программирование

Другие курсовые по предмету Компьютеры, программирование

mpt = class(TForm)

XPManifest1: TXPManifest;

Image1: TImage;

private

{ Private declarations }

public

{ Public declarations }

end;

 

var

FormPrompt: TFormPrompt;

 

implementation

 

{$R *.dfm}

 

end.

 

Файл проекта COM-сервера MyServer.dpr

 

library MyServer;

 

{ Important note about DLL memory management: ShareMem must be the first unit in your librarys USES clause AND your projects (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }

 

uses

SysUtils,

ComServ,

UComRiad in UComRiad.pas,

UCom_Tlb in UCom_Tlb.pas,

Classes,

MyServer_TLB in MyServer_TLB.pas;

 

exports

DllGetClassObject,

DllCanUnloadNow,

DllRegisterServer,

DllUnregisterServer;

 

{$R *.TLB}

 

{$R *.res}

 

begin

end.

 

Файл описания COM- класса UComRiad.pas

 

unit UComRiad;

 

{$WARN SYMBOL_PLATFORM OFF}

 

interface

 

uses

Windows, ActiveX, Classes, ComObj, Chart, Grids, Math, SysUtils, IniFiles,

UCom_Tlb, ExtCtrls;

 

type

TRiad = class(TComObject, IComRiad)

protected

IniFile : TIniFile; //Объект Ini-файла

w : integer;

 

public

Procedure Create(AIniFileName : string); stdcall;

Destructor Destroy;

procedure Graphic(AChart:TChart); stdcall; //Постоение графика

procedure Table(AStringGrid:TStringGrid); stdcall; //Вывод в таблицу

procedure WriteToIniFile; stdcall; //Запись в Ini-файл

procedure ReadFromIniFile; stdcall; //Чтение из Ini-файла

function GetW : integer; stdcall; //Получить w

procedure SetW; stdcall; //Установить w

function F(w:integer; t:extended):extended;stdcall;//Вычисление суммы

private

 

end;

 

implementation

 

uses ComServ, Dialogs, Graphics, UnitMain;

const P=500;

const x=1;

const TimeStart=0; //Время начала отсчета

const TimeEnd=100; //Время окончания отсчета

const TimeStep=0.5; //Шаг дискретизация времени

 

Procedure TRiad.Create(AIniFileName : string);

begin

//Создать объект Ini-файла

IniFile:= TIniFile.Create(AIniFileName);

end;//TRod.Create

 

Destructor TRiad.Destroy;

begin //Не используется

//Удалить из Heap объект Ini-файла

if Assigned(IniFile) then

begin

IniFile.Free;

IniFile:= NIL;

end;

end;//TRod.Create

 

procedure TRiad.Graphic(AChart : TChart);

//Построение графика

var

time : extended;

Y1, Y2 : extended;

begin

Time:= TimeStart;

AChart.Series[0].Clear; //Очистить Series[0]

AChart.Series[1].Clear; //Очистить Series[1]

AChart.BottomAxis.Increment:= Floor((TimeEnd - TimeStart) / 5);

//Занести значения в Series

while(time <= TimeEnd) do

begin

Y1:= F(w,time);

Y2:= F(w,time);

AChart.Series[0].AddXY(time, Y1);

AChart.Series[1].AddXY(time, Y2);

time:= time + TimeStep / 4;

end;

end;//TRiad.Graphic

 

function TRiad.F(w : integer;t : extended) : extended;

//вычисление функции

var

j:integer;

begin

F:=(2*P/x)*(sin(w*t)-1/2*sin(2*w*t)+1/3*sin(3*w*t)-1/4*sin(4*w*t))

end;//TRiad.F

 

procedure TRiad.Table(AStringGrid : TStringGrid);

//Вывод информации в таблицу

var

k : integer;

time : extended;

y: extended;

begin

k:= 0;

time:= TimeStart;

 

while (time <= TimeEnd) do

begin

inc(k);

y:= F(w, time);

Form1.StringGrid1.Cells[2,k]:= FloatToStrF(y , ffFixed, 5, 3);

time:= time + TimeStep;

end;

end;//TRiad.Table

 

procedure TRiad.WriteToIniFile;

//запись в Ini-файл

begin

IniFile.WriteInteger(Parameters, W, W);

IniFile.UpdateFile;//очистка буфера и запись файла на диск

end;//TRiad.WriteToIniFile

 

procedure TRiad.ReadFromIniFile;

//чтение из Ini-файла

begin

W:= IniFile.ReadInteger(Parameters, W, w);

end;//TRiad.ReadFromIniFile

function TRiad.GetW :integer;

begin

result:= W;

end;//TRiad.GetW

 

procedure TRiad.SetW;

begin

if Form1.RadioGroup1.ItemIndex=-1 then

MessageDlg(Pchar(Не выбрано значение w!!!),mtError,[mbOk],0);

if Form1.RadioGroup1.ItemIndex =0 then

begin

Form1.Label10.Caption:=1;

w:=1;

end

else if Form1.RadioGroup1.ItemIndex =1 then

begin

Form1.label10.Caption:=3;

w:=3;

end

else

begin

Form1.label10.Caption:=5;

w:=5;

end ;

end;//TRiad.SetW

 

initialization

TComObjectFactory.Create(ComServer, TRiad, Class_ServerRiad,

ServerRiad, , ciMultiInstance, tmApartment);

end.

Файл библиотеки типов COM- класса Ucom_Tlb.pas

 

unit UCom_Tlb;

interface

uses Chart, Grids, StdCtrls, ExtCtrls;

const

Class_ServerRiad: TGUID = {1CB7B26E-5BAF-4BA7-8F17-EA174D7CD750};

Type

IComRiad = interface

[{1326DD83-DB3E-4054-9572-CFB9EAE3FE95}]

Procedure Create(AIniFileName : string); stdcall;

procedure Graphic(AChart:TChart); stdcall; //Постоение графика

procedure Table(AStringGrid:TStringGrid); stdcall; //Вывод в таблицу

procedure WriteToIniFile; stdcall; //Запись в Ini-файл

procedure ReadFromIniFile; stdcall; //Чтение из Ini-файла

function Getw : integer; stdcall; //Получить w

procedure Setw; stdcall; //Установить w

function F(w:integer; t:extended):extended;stdcall;//Вычисление суммы

 

end;

implementation

end.