247431 (Программная реализация разложения временного процесса в тригонометрический ряд), страница 3
Описание файла
Документ из архива "Программная реализация разложения временного процесса в тригонометрический ряд", который расположен в категории "". Всё это находится в предмете "информатика" из 1 семестр, которые можно найти в файловом архиве . Не смотря на прямую связь этого архива с , его также можно найти и в других разделах. Архив можно найти в разделе "курсовые/домашние работы", в предмете "информатика, программирование" в общих файлах.
Онлайн просмотр документа "247431"
Текст 3 страницы из документа "247431"
uses UnitRiad, UnitGraphic;
{$R *.dfm}
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.FormActivate(Sender: TObject);
var i:integer;
begin
//По умолчанию установить работу с обычным (классическим) объектом
Flag:= false;
//Имя Ini-файла сохранения параметров
IniFileName:= GetCurrentDir+'\Riad.ini';
//Создать обычный объект
Riad:= TRiad.Create(IniFileName);
//Считать данные из Ini-файла
Riad.ReadFromIniFile;
//Вычисление и вывод данных в таблицу
Riad.Table(StringGrid1);
StringGrid1.Cells[0,0]:='Номер' ;
StringGrid1.Cells[1,0]:='Время(с)';
StringGrid1.Cells[2,0]:='F{t} при w=1';
StringGrid1.Cells[3,0]:='F{t} при w=3';
StringGrid1.Cells[4,0]:='F{t} при w=5';
for i:=1 to 201 do
StringGrid1.Cells[0,i]:=IntToStr(i) ;
for i:=0 to 201 do
begin
StringGrid1.Cells[1,i+1]:=FloatToStr(0.5*i)
end;
label10.Caption:='';
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var i:integer;
begin
Riad.SetW();
//Вычисление и вывод данных в таблицу
Riad.Table(StringGrid1);
end;
procedure TForm1.BitBtn4Click(Sender: TObject);
var i:integer;
begin
for i:=0 to 201 do
begin
StringGrid1.Cells[2,i+1]:='';
StringGrid1.Cells[3,i+1]:='';
StringGrid1.Cells[4,i+1]:='';
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
FormGraphic.Show;
end;
procedure TForm1.N4Click(Sender: TObject);
Type
//Процедурный тип для вызова процедуры из DLL
TProc = procedure(AOwner:TComponent);
var
Handle : LongInt; //Дескриптор библиотеки
ShowAbout : TProc; //Переменая для вызова функции из DLLbegin
begin
//Получить значение дескриптора загруженной библиотеки
Handle:=LoadLibrary('About.dll');
//Проверить существование библиотеки
if Handle = 0 then
begin
ShowMessage('Библиотека не найдена : About.dll');
exit;
end;
//Получить адрес вызываемой функции
@ShowAbout:= GetProcAddress(Handle, PChar('ShowAbout'));
//Вызов функции, показывающей форму About
ShowAbout(Application);
FreeLibrary(Handle); //Выгрузка библиотеки
end;
procedure TForm1.PresentationClick(Sender: TObject);
var
name : string;
pw : TOleEnum;
begin
//Запуск презетации
Name:= ExtractFileDir(Application.ExeName) + '\Vremennoj process.ppsx';
PowerPointApplication1.Activate;
PowerPointApplication1.Presentations.Open(Name, pw, pw, pw);
PowerPointApplication1.Presentations.Item(1).SlideShowSettings.Run;
//Другой способ запуска
// ShellExecute(Application.MainForm.Handle,PChar('Open'),
// PChar('Riad.pps'), NIL, PChar(''), sw_ShowNormal);
end;//TFormMain.PresentationClick
procedure TForm1.Word1Click(Sender: TObject);
begin //Отчет в Word
ReportWord(StringGrid1);
end;//TFormMain.Word1Click
Procedure TForm1.ReportExcel(AStringGrid : TStringGrid);
//Отчет в Excel
var
Excel : variant;
WorkBook : variant; //Рабочая книга
i, j : integer;
begin
//Cоздать форму для графика
FormGraphic:= TFormGraphic.Create(Form1);
//Создать Соm-объект
Excel:= CreateOleObject('Excel.Application');
//Отключить реакцию на внешние события-для ускорения процесса передачи данных
Excel.Application.EnableEvents:= false;
//Добавить рабочую книгу
WorkBook:= Excel.WorkBooks.Add;
//Изменение ширины столбцов
for j:=0 to AStringGrid.ColCount do
WorkBook.WorkSheets[1].Columns[j+1].ColumnWidth:= 10;
//Вывод строки
WorkBook.WorkSheets[1].Cells[1,1]:= 'Отчет о колебаниях стержня';
//Заполнение ячеек таблицы Excel значениями из StringGrid
//Нумерация ячеек в Excel начинается с 1 и идет в формате строка-столбец
for i:= 1 to AStringGrid.RowCount + 1 do
for j:= 0 to AStringGrid.ColCount do
WorkBook.WorkSheets[1].Cells[i+1, j+1]:= AStringGrid.Cells[j, i-1];
//Вставит изображение графика в Excel
WorkBook.WorkSheets[1].Shapes.AddPicture(GetCurrentDir+'\PictureWord.bmp',
True, True, 0, (AStringGrid.RowCount+2)*12.5+10, FormGraphic.Chart1.Width*0.8,
FormGraphic.Chart1.Height*0.8);
//Уничтожить форму
FormGraphic.Release;
FormGraphic:= NIL;
//Показать Excel
Excel.Visible:=true;
end;//TFormMain.ReportExcel
Procedure TForm1.ReportWord(AStringGrid : TStringGrid);
//Отчет в Word
var
i,j,k : integer;
a,b,c : OleVariant;
wa : TWordApplication; //WordApplication
wd : TWordDocument; //WordDocument
begin
//Создать форму для графика
FormGraphic:= TFormGraphic.Create(Form1);
//Создать com-объект
wa:= TWordApplication.Create(Form1);
//Подключиться к серверу Word
wa.Connect;
//Добавить новый документ
wa.Documents.Add(EmptyParam, EmptyParam, EmptyParam, EmptyParam);
wd:= TWordDocument.Create(Form1);
wd.ConnectTo(wa.ActiveDocument);
//Отменить проверку правописания
wa.Options.CheckSpellingAsYouType:=False;
//Отменить проверку орфографии
wa.Options.CheckGrammarAsYouType:=False;
a:= 0;
b:= 0;
wd.Range.InsertAfter('Отчет');
c:= Length(wd.Range.Text) - 1;
a:= c;
b:= c + 10;
//Добавить таблицу
wd.Tables.Add(wd.Range(a), AStringGrid.RowCount,
AStringGrid.ColCount, EmptyParam, EmptyParam);
k:= 1;
//Перенести данные из StringGrid в таблицу
for i:= 1 to AStringGrid.RowCount do
for j:= 1 to AStringGrid.ColCount do
wd.Tables.Item(k).Cell(i,j).Range.Text:= AStringGrid.Cells[j-1, i-1];
//Загрузить изображение в Image
FormGraphic.Image1.Picture.LoadFromFile('PictureWord.bmp');
//Поместить изображение в буфер обмена
Clipboard.Assign(FormGraphic.Image1.Picture);
c:= Length(wd.Range.Text) - 1;
a:= c;
//Вставить изображение из буфера обмена
wa.Selection.Paste;
//Показать Word
wa.Visible:= true;
//Уничтожить форму
FormGraphic.Release;
FormGraphic:= NIL;
end;//TFormMain.ReportWord
procedure TForm1.Excel1Click(Sender: TObject);
begin
ReportExcel(StringGrid1);
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
WinExec('hh.exe 1.chm',SW_SHOW);
end;
end.
Файл вывода графика UnitGraphic.pas
unit UnitGraphic;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, Series, StdCtrls, ExtCtrls, TeeProcs, Chart, XPMan,
TeeFunci, Buttons;
type
TFormGraphic = class(TForm)
Chart1: TChart;
Button1: TButton;
XPManifest1: TXPManifest;
Series1: TLineSeries;
Series2: TLineSeries;
TeeFunction1: TAddTeeFunction;
Series3: TLineSeries;
Image1: TImage;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
procedure Button1Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormGraphic: TFormGraphic;
implementation
uses UnitRiad;
{$R *.dfm}
procedure TFormGraphic.Button1Click(Sender: TObject);
begin
Chart1.Series[0].Clear;
Chart1.Series[1].Clear;
Chart1.Series[2].Clear;
Close;
end;//TFormGraphic.Button1Click
procedure TFormGraphic.BitBtn1Click(Sender: TObject);
begin
Riad.Graphic1(FormGraphic.Chart1);
end;
procedure TFormGraphic.BitBtn2Click(Sender: TObject);
begin
Riad.Graphic2(FormGraphic.Chart1);
end;
procedure TFormGraphic.BitBtn3Click(Sender: TObject);
begin
Riad.Graphic3(FormGraphic.Chart1);
end;
procedure TFormGraphic.BitBtn4Click(Sender: TObject);
begin
Chart1.Series[0].Clear;
Chart1.Series[1].Clear;
Chart1.Series[2].Clear;
end;
end.
end.
Файл реализации класса - UnitRiad.pas
unit UnitRiad;
interface
uses Chart, Series, Math, Grids, SysUtils, Types, Graphics, IniFiles, Messages, Dialogs, StdCtrls, Variants, Classes, Controls, Forms,
ExtCtrls, Buttons, Menus;
Type
TRiad = class //класс
private
IniFile : TIniFile; //Объект Ini-файла
w: integer;
public
Constructor Create(AIniFileName : string);
Destructor Destroy;
procedure Graphic1(AChart:TChart); //Постоение графика
procedure Graphic2(AChart:TChart); //Постоение графика
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