Программная реализация разложения временного процесса в тригонометрический ряд
procedure Graphic3(AChart:TChart); //Постоение графика
procedure Table(AStringGrid:TStringGrid); //Вывод в таблицу
procedure WriteToIniFile; //Запись в Ini-файл
procedure ReadFromIniFile; //Чтение из Ini-файла
function GetW : integer; //Получить w
procedure SetW; //Установить w
function F(w:integer;t:extended):extended;//Вычисление суммы
//property ww : integer read GetW write SetW;
private
end;
var
Riad : TRiad; //Объект
implementation
uses UnitMain, UnitGraphic;
const P=500;
const x=1;
const TimeStart=0; //Время начала отсчета
const TimeEnd=100; //Время окончания отсчета
const TimeStep=0.5; //Шаг дискретизация времени
Constructor TRiad.Create(AIniFileName : string);
begin
//Создать объект Ini-файла
IniFile:= TIniFile.Create(AIniFileName);
end;//TRiad.Create
Destructor TRiad.Destroy;
begin
//Удалить из Heap объект Ini-файла
if Assigned(IniFile) then
begin
IniFile.Free;
IniFile:= NIL;
end;
end;//TRiad.Create
procedure TRiad.Graphic1(AChart : TChart);
//Построение графика
var
time : extended;
Y: extended;
begin
Time:= TimeStart;
AChart.Series[0].Clear; //Очистить Series[0]
AChart.BottomAxis.Increment:= Floor((TimeEnd - TimeStart) / 5);
//Занести значения в Series
while(time <= TimeEnd) do
begin
Y:= F(1,time);
AChart.Series[0].AddXY(time, Y);
time:= time + TimeStep / 4;
end;
end;//TRiad.Graphic1
procedure TRiad.Graphic2(AChart : TChart);
//Построение графика
var
time : extended;
Y: extended;
begin
Time:= TimeStart;
AChart.Series[1].Clear; //Очистить Series[0]
AChart.BottomAxis.Increment:= Floor(( TimeEnd- TimeStart) / 5);
//Занести значения в Series
while(time <= TimeEnd) do
begin
Y:= F(3,time);
AChart.Series[1].AddXY(time, Y);
time:= time + TimeStep / 4;
end;
end;//TRiad.Graphic2
procedure TRiad.Graphic3(AChart : TChart);
//Построение графика
var
time : extended;
Y: extended;
begin
Time:= TimeStart;
AChart.Series[2].Clear; //Очистить Series[0]
AChart.BottomAxis.Increment:= Floor((TimeEnd - TimeStart) / 5);
//Занести значения в Series
while(time <= TimeEnd) do
begin
Y:= F(5,time);
AChart.Series[2].AddXY(time, Y);
time:= time + TimeStep / 4;
end;
end;//TRiad.Graphic3
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;
if w=1 then
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
else if w=3 then
while (time <= TimeEnd) do
begin
inc(k);
y:= F(w, time);
Form1.StringGrid1.Cells[3,k]:= FloatToStrF(y , ffFixed, 5, 3);
time:= time + TimeStep;
end
else if w=5 then
while (time <= TimeEnd) do
begin
inc(k);
y:= F(w, time);
Form1.StringGrid1.Cells[4,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
end.
Файл описания динамической библиотеки About.dpr
library About;
{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (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,
Classes,
Forms,
UnitAbout in 'UnitAbout.pas' {FormAbout};
{$R *.res}
//показать форму
procedure ShowAbout(AOwner:TComponent);
var
Form:TFormAbout;
begin
Form:=TFormAbout.Create(AOwner); //создать форму
Form.ShowModal; //показать форму
Form.Free; //уничтожить форму
end;
exports ShowAbout;
begin
end.
unit UnitAbout;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, XPMan, Buttons;
type
TFormAbout = class(TForm)
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
BitBtn1: TBitBtn;
Label5: TLabel;
XPManifest1: TXPManifest;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormAbout: TFormAbout;
implementation
{$R *.dfm}
procedure TFormAbout.BitBtn1Click(Sender: TObject);
begin
Close;
end;
end.
Файл описания динамической библиотеки Prompt.dpr
library Prompt;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (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,
Classes,
Windows,
UnitPrompt in 'UnitPrompt.pas' {FormPrompt};
{$R *.res}
//Показать заставку
procedure ShowPrompt(AOwner:TComponent);
var
Time:extended;
Form:TFormPrompt;
begin
Form:=TFormPrompt.Create(AOwner); //Создать форму
Time:=GetTickCount/1000; //Запомнить время
Form.Show; //Показать форму
Form.Repaint; //Перерисовать форму
//Пока не вышел лимит времени - ничего не делать
while GetTickCount/1000<Time+4 do;
Form.Close; //Закрыть форму
Form.Free; //Уничтожить форму
end;
exports ShowPrompt;
begin
end.
unit UnitPrompt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, XPMan;
type
TFormPrompt = 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 library's USES clause AND your project's (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.