/
unitframeworddisplay.pas
99 lines (76 loc) · 2.07 KB
/
unitframeworddisplay.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
unit UnitFrameWordDisplay;
// Copyright 2022-2024 Zoran Vučenović
// SPDX-License-Identifier: Apache-2.0
{$mode objfpc}{$H+}
{$i zxinc.inc}
interface
uses
Classes, SysUtils, Forms, Controls, ExtCtrls, StdCtrls;
type
TFrameWordDisplay = class(TFrame)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
PanelBin: TPanel;
PanelHex: TPanel;
private
FByteMode: Boolean;
FValue: Word;
procedure SetByteMode(AValue: Boolean);
procedure SetValue(AValue: Word);
public
constructor Create(TheOwner: TComponent); override;
class function MakeNew(const Title: String): TFrameWordDisplay;
procedure SetTitle(const S: String);
property Value: Word read FValue write SetValue;
property ByteMode: Boolean read FByteMode write SetByteMode;
end;
implementation
{$R *.lfm}
{ TFrameWordDisplay }
procedure TFrameWordDisplay.SetValue(AValue: Word);
begin
if not FByteMode then begin
FValue := AValue;
Label3.Caption := HexStr(WordRec(FValue).Hi, 2);
Label1.Caption := binStr(WordRec(FValue).Hi, 8);
end else begin
FValue := AValue and $FF;
Label3.Caption := '';
Label1.Caption := '';
end;
Label4.Caption := HexStr(WordRec(FValue).Lo, 2);
Label2.Caption := binStr(WordRec(FValue).Lo, 8);
Label5.Caption := IntToStr(FValue);
end;
procedure TFrameWordDisplay.SetByteMode(AValue: Boolean);
begin
if FByteMode <> AValue then begin
FByteMode := AValue;
SetValue(FValue);
end;
end;
constructor TFrameWordDisplay.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FByteMode := False;
Label6.Constraints.MinWidth := Label6.Width;
Label6.AutoSize := True;
end;
class function TFrameWordDisplay.MakeNew(const Title: String
): TFrameWordDisplay;
begin
Result := TFrameWordDisplay.Create(nil);
Result.SetTitle(Title);
end;
procedure TFrameWordDisplay.SetTitle(const S: String);
begin
Label6.Caption := S;
end;
end.