我刚刚发现了 Delphi 的 livebindings。并创建了我的第一个组件来处理变频器的控制字。它本身的组件似乎可以在表单设计器中很好地测试它。但是,编译和运行应用程序的东西不起作用。来自 livbindings 的屏幕截图如下:
这是组件的代码
unit cBits2Byte;
interface
uses
System.SysUtils, System.Classes;
type
TBits2Byte = class(TComponent)
private
{ Private declarations }
fBit00, fBit01, fBit02, fBit03, fBit04, fBit05, fBit06, fBit07: Boolean;
function bitstate(sfr, bit: Byte): Boolean;
function ReadByte: Byte;
procedure WriteByte(aByte: Byte);
published
{ Published declarations }
property char: byte read ReadByte write WriteByte;
property Bit00: Boolean read fBit00 write fBit00;
property Bit01: Boolean read fBit01 write fBit01;
property Bit02: Boolean read fBit02 write fBit02;
property Bit03: Boolean read fBit03 write fBit03;
property Bit04: Boolean read fBit04 write fBit04;
property Bit05: boolean read fBit05 write fBit05;
property Bit06: boolean read fBit06 write fBit06;
property Bit07: boolean read fBit07 write fBit07;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TBits2Byte]);
end;
function TBits2Byte.bitstate(sfr, bit: Byte): Boolean;
begin
Result := Boolean( (sfr shr bit) And $01);
end;
function TBits2Byte.ReadByte: Byte;
begin
Result := (Ord(Bit07) shl 7) Or
(Ord(Bit06) shl 6) Or
(Ord(Bit05) shl 5) Or
(Ord(Bit04) shl 4) Or
(Ord(Bit03) shl 3) Or
(Ord(Bit02) shl 2) Or
(Ord(Bit01) shl 1) Or
(Ord(Bit00));
end;
procedure TBits2Byte.WriteByte(aByte: Byte);
begin
Bit00 := bitstate(aByte, 0);
Bit01 := bitstate(aByte, 1);
Bit02 := bitstate(aByte, 2);
Bit03 := bitstate(aByte, 3);
Bit04 := bitstate(aByte, 4);
Bit05 := bitstate(aByte, 5);
Bit06 := bitstate(aByte, 6);
Bit07 := bitstate(aByte, 7);
end;
end.
那么,将这项工作作为活体绑定,我缺少什么?