-
Notifications
You must be signed in to change notification settings - Fork 1
/
unitdlgstartadress.pas
104 lines (90 loc) · 2.44 KB
/
unitdlgstartadress.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
unit UnitDlgStartAdress;
// Copyright 2022-2024 Zoran Vučenović
// SPDX-License-Identifier: Apache-2.0
{$mode ObjFPC}{$H+}
{$i zxinc.inc}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Spin, StdCtrls,
ButtonPanel, ExtCtrls;
type
TFormDlgStartAddress = class(TForm)
ButtonPanel1: TButtonPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
SpinEdit1: TSpinEdit;
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCreate(Sender: TObject);
private
FilePath: AnsiString;
procedure FormFirstShow(Sender: TObject);
public
class function ShowDlgStartAddress(var AAddress: Word; const LowAdr,
HighAdr: Word; const AFilePath: AnsiString): TModalResult;
end;
var
FormDlgStartAddress: TFormDlgStartAddress;
implementation
{$R *.lfm}
{ TFormDlgStartAddress }
procedure TFormDlgStartAddress.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
if ModalResult = mrOK then begin
CanClose := (SpinEdit1.Value <= SpinEdit1.MaxValue) and (SpinEdit1.Value >= SpinEdit1.MinValue);
end;
end;
procedure TFormDlgStartAddress.FormCreate(Sender: TObject);
begin
Panel1.Constraints.MinHeight := Panel1.Height;
Panel1.AutoSize := True;
FilePath := '';
AddHandlerFirstShow(@FormFirstShow);
end;
procedure TFormDlgStartAddress.FormFirstShow(Sender: TObject);
var
S: RawByteString;
begin
S := Trim(ExtractFileName(FilePath));
if S = '' then begin
S := ' ';
Panel3.ShowHint := False;
end else begin
Panel3.Hint := FilePath;
Panel3.ShowHint := True;
end;
Label3.Caption := S;
end;
class function TFormDlgStartAddress.ShowDlgStartAddress(var AAddress: Word;
const LowAdr, HighAdr: Word; const AFilePath: AnsiString): TModalResult;
var
F: TFormDlgStartAddress;
M: TModalResult;
begin
if LowAdr = HighAdr then begin
AAddress := LowAdr;
Result := mrOK;
end else if LowAdr < HighAdr then begin
Result := mrNoToAll;
F := TFormDlgStartAddress.Create(nil);
try
F.SpinEdit1.MinValue := LowAdr;
F.SpinEdit1.MaxValue := HighAdr;
F.SpinEdit1.Value := AAddress;
F.FilePath := AFilePath;
F.Label1.Caption := Format('Start address (%d — %d):', [LowAdr, HighAdr]);
M := F.ShowModal;
if M = mrOK then begin
AAddress := F.SpinEdit1.Value;
end;
Result := M;
finally
F.Free;
end;
end;
end;
end.