📄 jvdbradiopanel.pas
字号:
begin
Result := FDataLink.Edit;
end;
procedure TJvDBRadioPanel.Change;
begin
if Assigned(FOnChange) then
FOnChange(Self);
end;
procedure TJvDBRadioPanel.Click;
begin
if not FInSetValue then
begin
inherited Click;
if ItemIndex >= 0 then
Value := GetButtonValue(ItemIndex);
if FDataLink.Editing then
FDataLink.Modified;
end;
end;
procedure TJvDBRadioPanel.EnabledChanged;
var
I: Integer;
begin
inherited EnabledChanged;
for I := 0 to FButtons.Count - 1 do
TGroupButton(FButtons[I]).Enabled := Enabled;
end;
procedure TJvDBRadioPanel.DoExit;
begin
try
FDataLink.UpdateRecord;
except
if ItemIndex >= 0 then
TRadioButton(Controls[ItemIndex]).SetFocus
else
TRadioButton(Controls[0]).SetFocus;
raise;
end;
inherited DoExit;
end;
procedure TJvDBRadioPanel.FontChanged;
begin
inherited FontChanged;
ArrangeButtons;
end;
procedure TJvDBRadioPanel.CMGetDataLink(var Msg: TMessage);
begin
Msg.Result := Integer(FDataLink);
end;
procedure TJvDBRadioPanel.DataChange(Sender: TObject);
begin
if FDataLink.Field <> nil then
Value := FDataLink.Field.Text
else
Value := '';
end;
function TJvDBRadioPanel.ExecuteAction(Action: TBasicAction): Boolean;
begin
Result := inherited ExecuteAction(Action) or (DataLink <> nil) and
DataLink.ExecuteAction(Action);
end;
procedure TJvDBRadioPanel.FlipChildren(AllLevels: Boolean);
begin
{ The radio buttons are flipped using BiDiMode }
end;
function TJvDBRadioPanel.GetButtons(Index: Integer): TRadioButton;
begin
Result := TRadioButton(FButtons[Index]);
end;
function TJvDBRadioPanel.GetButtonValue(Index: Integer): string;
begin
if (Index < FValues.Count) and (FValues[Index] <> '') then
Result := FValues[Index]
else
if Index < Items.Count then
Result := Items[Index]
else
Result := '';
end;
procedure TJvDBRadioPanel.GetChildren(Proc: TGetChildProc; Root: TComponent);
begin
end;
function TJvDBRadioPanel.GetDataField: string;
begin
Result := FDataLink.FieldName;
end;
function TJvDBRadioPanel.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
function TJvDBRadioPanel.GetField: TField;
begin
Result := FDataLink.Field;
end;
function TJvDBRadioPanel.GetReadOnly: Boolean;
begin
Result := FDataLink.ReadOnly;
end;
procedure TJvDBRadioPanel.ItemsChange(Sender: TObject);
begin
if not FReading then
begin
if FItemIndex >= FItems.Count then
FItemIndex := FItems.Count - 1;
UpdateButtons;
end;
end;
procedure TJvDBRadioPanel.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
case Key of
Backspace, ' ':
FDataLink.Edit;
Esc:
FDataLink.Reset;
end;
end;
procedure TJvDBRadioPanel.Loaded;
begin
inherited Loaded;
ArrangeButtons;
end;
procedure TJvDBRadioPanel.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (FDataLink <> nil) and (AComponent = DataSource) then
DataSource := nil;
end;
procedure TJvDBRadioPanel.ReadState(Reader: TReader);
begin
FReading := True;
inherited ReadState(Reader);
FReading := False;
UpdateButtons;
end;
procedure TJvDBRadioPanel.SetButtonCount(Value: Integer);
begin
while FButtons.Count < Value do
TGroupButton.InternalCreate(Self);
while FButtons.Count > Value do
TGroupButton(FButtons.Last).Free;
end;
procedure TJvDBRadioPanel.SetColumns(Value: Integer);
begin
if Value < 1 then
Value := 1;
if Value > 16 then
Value := 16;
if FColumns <> Value then
begin
FColumns := Value;
ArrangeButtons;
Invalidate;
end;
end;
procedure TJvDBRadioPanel.SetDataField(const Value: string);
begin
FDataLink.FieldName := Value;
end;
procedure TJvDBRadioPanel.SetDataSource(Value: TDataSource);
begin
FDataLink.DataSource := Value;
if Value <> nil then
Value.FreeNotification(Self);
end;
procedure TJvDBRadioPanel.SetItemIndex(Value: Integer);
begin
if FReading then
FItemIndex := Value
else
begin
if Value < -1 then
Value := -1;
if Value >= FButtons.Count then
Value := FButtons.Count - 1;
if FItemIndex <> Value then
begin
if FItemIndex >= 0 then
TGroupButton(FButtons[FItemIndex]).Checked := False;
FItemIndex := Value;
if FItemIndex >= 0 then
TGroupButton(FButtons[FItemIndex]).Checked := True;
end;
end;
end;
function TJvDBRadioPanel.GetItems: TStrings;
begin
Result := FItems;
end;
procedure TJvDBRadioPanel.SetItems(Value: TStrings);
begin
FItems.Assign(Value);
DataChange(Self);
end;
procedure TJvDBRadioPanel.SetReadOnly(Value: Boolean);
begin
FDataLink.ReadOnly := Value;
end;
procedure TJvDBRadioPanel.SetValue(const Value: string);
var
I, Index: Integer;
begin
if FValue <> Value then
begin
FInSetValue := True;
try
Index := -1;
for I := 0 to Items.Count - 1 do
if Value = GetButtonValue(I) then
begin
Index := I;
Break;
end;
ItemIndex := Index;
finally
FInSetValue := False;
end;
FValue := Value;
Change;
end;
end;
function TJvDBRadioPanel.GetValues: TStrings;
begin
Result := FValues;
end;
procedure TJvDBRadioPanel.SetValues(Value: TStrings);
begin
FValues.Assign(Value);
DataChange(Self);
end;
function TJvDBRadioPanel.UpdateAction(Action: TBasicAction): Boolean;
begin
Result := inherited UpdateAction(Action) or (DataLink <> nil) and
DataLink.UpdateAction(Action);
end;
procedure TJvDBRadioPanel.UpdateButtons;
var
I: Integer;
begin
SetButtonCount(FItems.Count);
for I := 0 to FButtons.Count - 1 do
TGroupButton(FButtons[I]).Caption := FItems[I];
if FItemIndex >= 0 then
begin
FUpdating := True;
TGroupButton(FButtons[FItemIndex]).Checked := True;
FUpdating := False;
end;
ArrangeButtons;
Invalidate;
end;
procedure TJvDBRadioPanel.UpdateData(Sender: TObject);
begin
if FDataLink.Field <> nil then
FDataLink.Field.Text := Value;
end;
function TJvDBRadioPanel.UseRightToLeftAlignment: Boolean;
begin
Result := inherited UseRightToLeftAlignment;
end;
procedure TJvDBRadioPanel.BoundsChanged;
begin
inherited BoundsChanged;
ArrangeButtons;
end;
{$IFDEF UNITVERSIONING}
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -