Y:= F(1,time);
AChart.Series[0].AddXY(time,Y);
time:= time +TimeStep / 4;
end;
end;//TRiad.Graphic1
procedureTRiad.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
procedureTRiad.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
functionTRiad.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
procedureTRiad.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=3then
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=5then
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
procedureTRiad.WriteToIniFile;
//запись вIni-файл
begin
IniFile.WriteInteger('Parameters','W', W);
IniFile.UpdateFile;//очистка буфера и запись файла надиск
end;//TRiad.WriteToIniFile
procedureTRiad.ReadFromIniFile;
//чтение изIni-файла
begin
W:=IniFile.ReadInteger('Parameters', 'W', w);
end;//TRiad.ReadFromIniFile
functionTRiad.GetW :integer;
begin
result:= W;
end;//TRiad.GetW
procedureTRiad.SetW;
begin
ifForm1.RadioGroup1.ItemIndex=-1 then
MessageDlg(Pchar('Невыбрано значение w!!!'),mtError,[mbOk],0);
ifForm1.RadioGroup1.ItemIndex =0 then
begin
Form1.Label10.Caption:='1';
w:=1;
end
else ifForm1.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.
library About;
{ Importantnote about DLL memory management: ShareMem must be the first unit in yourlibrary's USES clause AND your project's (select Project-View Source) USESclause if your DLL exports any procedures or functions that pass strings asparameters or function results. This
applies toall strings passed to and from your DLL--even those that are nested in recordsand classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memorymanager, 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}
//показать форму
procedureShowAbout(AOwner:TComponent);
var
Form:TFormAbout;
begin
Form:=TFormAbout.Create(AOwner);//создать форму
Form.ShowModal;//показать форму
Form.Free; //уничтожитьформу
end;
exportsShowAbout;
begin
end.
unitUnitAbout;
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;
procedureBitBtn1Click(Sender: TObject);
private
{ Privatedeclarations }
public
{ Publicdeclarations }
end;
var
FormAbout:TFormAbout;
implementation
{$R *.dfm}
procedureTFormAbout.BitBtn1Click(Sender: TObject);
begin
Close;
end;
end.
libraryPrompt;
{ Importantnote about DLL memory management: ShareMem must be the
first unit inyour library's USES clause AND your project's (select
Project-ViewSource) USES clause if your DLL exports any procedures or
functionsthat pass strings as parameters or function results. This
applies toall strings passed to and from your DLL--even those that
are nested inrecords and classes. ShareMem is the interface unit to
theBORLNDMM.DLL shared memory manager, which must be deployed along
with yourDLL. To avoid using BORLNDMM.DLL, pass string information
using PCharor ShortString parameters. }
uses
SysUtils,
Classes,
Windows,
UnitPrompt in'UnitPrompt.pas' {FormPrompt};
{$R *.res}
//Показать заставку
procedureShowPrompt(AOwner:TComponent);
var
Time:extended;
Form:TFormPrompt;
begin
Form:=TFormPrompt.Create(AOwner);//Создать форму
Time:=GetTickCount/1000; //Запомнитьвремя
Form.Show; //Показатьформу
Form.Repaint; //Перерисоватьформу
//Пока не вышел лимитвремени - ничего не делать
whileGetTickCount/1000<Time+4 do;
Form.Close; //Закрыть форму
Form.Free; //Уничтожитьформу
end;
exportsShowPrompt;
begin
end.
unitUnitPrompt;
interface
uses
Windows,Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ExtCtrls, XPMan;
type
TFormPrompt =class(TForm)
XPManifest1:TXPManifest;
Image1:TImage;
private
{ Privatedeclarations }
public
{ Publicdeclarations }
end;
var
FormPrompt:TFormPrompt;
implementation
{$R *.dfm}
end.
libraryMyServer;
{ Importantnote about DLL memory management: ShareMem must be the first unit in yourlibrary's USES clause AND your project's (select Project-View Source) USESclause if your DLL exports any procedures or functions that pass strings asparameters or function results. This applies to all strings passed to and fromyour DLL--even those that are nested in records and classes. ShareMem is theinterface unit to the BORLNDMM.DLL shared memory manager, which must bedeployed along with your DLL. To avoid using BORLNDMM.DLL, pass stringinformation using PChar or ShortString parameters. }
uses
SysUtils,
ComServ,
UComRiad in'UComRiad.pas',
UCom_Tlb in'UCom_Tlb.pas',
Classes,
MyServer_TLBin 'MyServer_TLB.pas';
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;
{$R *.TLB}
{$R *.res}
begin
end.
unit UComRiad;
{$WARNSYMBOL_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
ProcedureCreate(AIniFileName : string); stdcall;
DestructorDestroy;
procedureGraphic(AChart:TChart); stdcall; //Постоение графика
procedureTable(AStringGrid:TStringGrid); stdcall; //Вывод в таблицу
procedureWriteToIniFile; stdcall; //Запись в Ini-файл
procedureReadFromIniFile; stdcall; //Чтение из Ini-файла
function GetW: integer; stdcall; //Получить w
procedureSetW; stdcall; //Установить w
functionF(w:integer; t:extended):extended;stdcall;//Вычисление суммы
private
end;
implementation
uses ComServ,Dialogs, Graphics, UnitMain;
const P=500;
const x=1;
constTimeStart=0; //Время началаотсчета
const TimeEnd=100;//Время окончания отсчета
const TimeStep=0.5; //Шагдискретизация времени
ProcedureTRiad.Create(AIniFileName : string);
begin
//Создать объектIni-файла
IniFile:=TIniFile.Create(AIniFileName);
end;//TRod.Create
DestructorTRiad.Destroy;
begin //Не используется
//Удалить из Heap объектIni-файла
ifAssigned(IniFile) then
begin
IniFile.Free;
IniFile:= NIL;
end;
end;//TRod.Create
procedureTRiad.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
functionTRiad.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
procedureTRiad.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
procedureTRiad.WriteToIniFile;
//запись в Ini-файл
begin
IniFile.WriteInteger('Parameters','W', W);
IniFile.UpdateFile;//очисткабуфера и запись файла на диск
end;//TRiad.WriteToIniFile
procedureTRiad.ReadFromIniFile;
//чтение из Ini-файла
begin
W:=IniFile.ReadInteger('Parameters', 'W', w);
end;//TRiad.ReadFromIniFile
functionTRiad.GetW :integer;
begin
result:= W;
end;//TRiad.GetW
procedureTRiad.SetW;
begin
ifForm1.RadioGroup1.ItemIndex=-1 then
MessageDlg(Pchar('Не выбрано значение w!!!'),mtError,[mbOk],0);
ifForm1.RadioGroup1.ItemIndex =0 then
begin
Form1.Label10.Caption:='1';
w:=1;
end
else ifForm1.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}']
ProcedureCreate(AIniFileName : string); stdcall;
procedureGraphic(AChart:TChart); stdcall; //Постоение графика
procedureTable(AStringGrid:TStringGrid); stdcall; //Вывод в таблицу
procedureWriteToIniFile; stdcall; //Запись в Ini-файл
procedureReadFromIniFile; stdcall; //Чтение из Ini-файла
function Getw: integer; stdcall; //Получить w
procedureSetw; stdcall; //Установить w
functionF(w:integer; t:extended):extended;stdcall;//Вычисление суммы
end;
implementation
end.