1
0
mirror of https://github.com/loginov-dmitry/multithread.git synced 2025-07-14 09:44:31 +02:00

Ex10 converted to Lazarus

This commit is contained in:
loginov-dmitry
2024-10-13 19:03:46 +03:00
parent b55cb71ddf
commit c050b512ae
8 changed files with 244 additions and 7 deletions

2
.gitignore vendored
View File

@ -26,3 +26,5 @@ __history
/Ex8/lib
/Ex9/backup
/Ex9/lib
/Ex10/backup
/Ex10/lib

BIN
Ex10/Ex10ProjLaz.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

85
Ex10/Ex10ProjLaz.lpi Normal file
View File

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<SessionStorage Value="InProjectDir"/>
<Title Value="Ex10ProjLaz"/>
<Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
<Icon Value="0"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="LCL"/>
</Item>
</RequiredPackages>
<Units>
<Unit>
<Filename Value="Ex10ProjLaz.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="Ex10Unit.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit>
<Unit>
<Filename Value="..\CommonUtils\MTUtils.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="Ex10ProjLaz"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="..\CommonUtils"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

24
Ex10/Ex10ProjLaz.lpr Normal file
View File

@ -0,0 +1,24 @@
program Ex10ProjLaz;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
{$IFDEF HASAMIGA}
athreads,
{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, Ex10Unit, MTUtils;
{$R *.res}
begin
RequireDerivedFormResource:=True;
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

BIN
Ex10/Ex10ProjLaz.res Normal file

Binary file not shown.

View File

@ -69,7 +69,7 @@ object Form1: TForm1
object labPostMsgCount: TLabel
Left = 212
Top = 118
Width = 16
Width = 7
Height = 16
Caption = '0'
end

116
Ex10/Ex10Unit.lfm Normal file
View File

@ -0,0 +1,116 @@
object Form1: TForm1
Left = 0
Height = 181
Top = 0
Width = 452
Caption = 'Form1'
ClientHeight = 181
ClientWidth = 452
Color = clBtnFace
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Tahoma'
OnDestroy = FormDestroy
Position = poScreenCenter
object Label1: TLabel
Left = 8
Height = 16
Top = 72
Width = 64
Caption = 'Результат:'
end
object labResult: TLabel
Left = 78
Height = 16
Top = 72
Width = 7
Caption = '0'
end
object Label2: TLabel
Left = 8
Height = 16
Top = 96
Width = 119
Caption = 'Статус вычислений:'
end
object labThreadStateInfo: TLabel
Left = 132
Height = 16
Top = 97
Width = 18
Caption = '???'
end
object Label3: TLabel
Left = 8
Height = 16
Top = 136
Width = 243
Caption = 'Число вызовов обработчика сообщения:'
end
object labPostMsgProcessCount: TLabel
Left = 257
Height = 16
Top = 136
Width = 7
Caption = '0'
end
object Label4: TLabel
Left = 8
Height = 16
Top = 118
Width = 198
Caption = 'Число отправленных сообщений:'
end
object labPostMsgCount: TLabel
Left = 212
Height = 16
Top = 118
Width = 7
Caption = '0'
end
object Label5: TLabel
Left = 8
Height = 16
Top = 157
Width = 114
Caption = 'Поток завершился:'
end
object labEndWork: TLabel
Left = 128
Height = 16
Top = 157
Width = 18
Caption = '???'
end
object btnRunInParallelThread: TButton
Left = 8
Height = 33
Top = 8
Width = 217
Caption = 'Вычислить сумму ряда чисел до:'
TabOrder = 0
OnClick = btnRunInParallelThreadClick
end
object ProgressBar1: TProgressBar
Left = 8
Height = 17
Top = 49
Width = 436
Anchors = [akTop, akLeft, akRight]
TabOrder = 1
end
object edMaxValue: TEdit
Left = 232
Height = 24
Top = 16
Width = 89
TabOrder = 2
Text = '10000000'
end
object Timer1: TTimer
Interval = 100
OnTimer = Timer1Timer
Left = 304
Top = 120
end
end

View File

@ -1,10 +1,16 @@
unit Ex10Unit;
{$IFDEF FPC}{$CODEPAGE UTF8}{$H+}{$MODE DELPHI}{$ENDIF}
unit Ex10Unit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MTUtils, ComCtrls, ExtCtrls, StrUtils;
{$IFnDEF FPC}
Windows, Messages,
{$ELSE}
LCLIntf, LCLType, LMessages, {$IFDEF MSWINDOWS}Windows, Messages,{$ENDIF}
{$ENDIF}
SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, MTUtils, ComCtrls,
ExtCtrls, StrUtils;
const
UM_PROGRESS_CHANGE = WM_USER + 2;
@ -51,7 +57,7 @@ type
{ Private declarations }
FMyThread: TMyThread;
FPostMsgProcessCount: Integer;
procedure UMProgressChange(var Msg: TMessage); message UM_PROGRESS_CHANGE;
procedure UMProgressChange(var Msg: {$IFnDEF FPC}TMessage{$ELSE}TLMessage{$ENDIF}); message UM_PROGRESS_CHANGE;
public
{ Public declarations }
end;
@ -61,7 +67,11 @@ var
PostMessageCount: Integer;
implementation
{$R *.dfm}
{$IFnDEF FPC}
{$R *.dfm}
{$ELSE}
{$R *.lfm}
{$ENDIF}
procedure TForm1.btnRunInParallelThreadClick(Sender: TObject);
var
@ -96,7 +106,7 @@ begin
labEndWork.Caption := IfThen(FMyThread.EndWork, 'ДА', 'НЕТ');
end;
procedure TForm1.UMProgressChange(var Msg: TMessage);
procedure TForm1.UMProgressChange(var Msg: {$IFnDEF FPC}TMessage{$ELSE}TLMessage{$ENDIF});
var
ProgressData: TProgressData;
begin