⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rm_dctrl.pas

📁 report machine 2.3 功能强大
💻 PAS
📖 第 1 页 / 共 3 页
字号:
destructor TRMRadioButtonControl.Destroy;
begin
  FRadioButton.Free;
  inherited Destroy;
end;

procedure TRMRadioButtonControl.DefineProperties;
begin
  inherited DefineProperties;
  AddEnumProperty('Alignment',
    'taLeftJustify;taRightJustify',
    [taLeftJustify, taRightJustify]);
  AddProperty('Checked', [RMdtBoolean], nil);
  AddProperty('Caption', [RMdtString], nil);
end;

procedure TRMRadioButtonControl.SetPropValue(Index: string; Value: Variant);
begin
  inherited SetPropValue(Index, Value);
  Index := AnsiUpperCase(Index);
  if Index = 'ALIGNMENT' then
    FRadioButton.Alignment := Value
  else if Index = 'CHECKED' then
    FRadioButton.Checked := Value
  else if Index = 'CAPTION' then
    FRadioButton.Caption := Value
end;

function TRMRadioButtonControl.GetPropValue(Index: string): Variant;
begin
  Index := AnsiUpperCase(Index);
  Result := inherited GetPropValue(Index);
  if Result <> Null then Exit;
  if Index = 'ALIGNMENT' then
    Result := FRadioButton.Alignment
  else if Index = 'CHECKED' then
    Result := FRadioButton.Checked
  else if Index = 'CAPTION' then
    Result := FRadioButton.Caption
end;

procedure TRMRadioButtonControl.LoadFromStream(Stream: TStream);
begin
  inherited LoadFromStream(Stream);
  FRadioButton.Alignment := TAlignment(RMReadByte(Stream));
  FRadioButton.Checked := RMReadBoolean(Stream);
  FRadioButton.Caption := RMReadString(Stream);
end;

procedure TRMRadioButtonControl.SaveToStream(Stream: TStream);
begin
  LVersion := 0;
  inherited SaveToStream(Stream);
  RMWriteByte(Stream, Byte(FRadioButton.Alignment));
  RMWriteBoolean(Stream, FRadioButton.Checked);
  RMWriteString(Stream, FRadioButton.Caption);
end;

{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}
{ TRMListBoxControl }

constructor TRMListBoxControl.Create;
begin
  inherited Create;
  FListBox := TListBox.Create(nil);
  FListBox.Parent := RMDialogForm;
  AssignControl(FListBox);
  BaseName := 'ListBox';
  dx := 121; dy := 97;
end;

destructor TRMListBoxControl.Destroy;
begin
  FListBox.Free;
  inherited Destroy;
end;

procedure TRMListBoxControl.DefineProperties;
begin
  inherited DefineProperties;
  AddProperty('Items', [RMdtHasEditor, RMdtOneObject], LinesEditor);
  AddProperty('ItemIndex', [], nil);
  AddProperty('Items.Count', [], nil);
end;

procedure TRMListBoxControl.SetPropValue(Index: string; Value: Variant);
begin
  inherited SetPropValue(Index, Value);
  Index := AnsiUpperCase(Index);
  if Index = 'ITEMINDEX' then
    FListBox.ItemIndex := Value
end;

function TRMListBoxControl.GetPropValue(Index: string): Variant;
begin
  Index := AnsiUpperCase(Index);
  Result := inherited GetPropValue(Index);
  if Result <> Null then Exit;
  if Index = 'ITEMINDEX' then
    Result := FListBox.ItemIndex
  else if Index = 'ITEMS.COUNT' then
    Result := FListBox.Items.Count
end;

function TRMListBoxControl.DoMethod(const MethodName: string; Par1, Par2, Par3: Variant): Variant;
begin
  Result := inherited DoMethod(MethodName, Par1, Par2, Par3);
  if Result = Null then
    Result := LinesMethod(FListBox.Items, MethodName, 'ITEMS', Par1, Par2, Par3);
end;

procedure TRMListBoxControl.LoadFromStream(Stream: TStream);
begin
  inherited LoadFromStream(Stream);
  RMReadMemo(Stream, FListBox.Items);
end;

procedure TRMListBoxControl.SaveToStream(Stream: TStream);
begin
  LVersion := 0;
  inherited SaveToStream(Stream);
  RMWriteMemo(Stream, FListBox.Items);
end;

procedure TRMListBoxControl.LinesEditor(Sender: TObject);
begin
  with TRMLinesEditorForm.Create(nil) do
  begin
    M1.Lines := FListBox.Items;
    if (ShowModal = mrOk) and ((Restrictions and RMrfDontModify) = 0) then
    begin
      RMDesigner.BeforeChange;
      FListBox.Items := M1.Lines;
      RMDesigner.AfterChange;
    end;
    Free;
  end;
end;

{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}
{ TRMComboBoxControl }

constructor TRMComboBoxControl.Create;
begin
  inherited Create;
  FComboBox := TComboBox.Create(nil);
  FComboBox.Parent := RMDialogForm;
  FComboBox.OnDrawItem := ComboBoxDrawItem;
  FComboBox.OnKeyDown := OnKeyDown;
  AssignControl(FComboBox);
  BaseName := 'ComboBox';
  dx := 145; dy := 21;

  RMConsts['csDropDown'] := csDropDown;
  RMConsts['csDropDownList'] := csDropDownList;
  RMConsts['csLookup'] := csLookup;
end;

destructor TRMComboBoxControl.Destroy;
begin
  FComboBox.Free;
  inherited Destroy;
end;

procedure TRMComboBoxControl.OnKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if FComboBox.Style = csDropDownList then
  begin
    if (Key = VK_DELETE) or (Key = VK_BACK) then
      FComboBox.ItemIndex := -1;
  end;
end;

procedure TRMComboBoxControl.DefineProperties;
begin
  inherited DefineProperties;
  AddProperty('Items', [RMdtHasEditor, RMdtOneObject], LinesEditor);
  AddProperty('ItemIndex', [], nil);
  AddProperty('Items.Count', [], nil);
  AddEnumProperty('Style',
    'csDropDown;csDropDownList;csLookup', [csDropDown, csDropDownList, csLookup]);
  AddProperty('Text', [], nil);
end;

procedure TRMComboBoxControl.SetPropValue(Index: string; Value: Variant);
begin
  inherited SetPropValue(Index, Value);
  Index := AnsiUpperCase(Index);
  if Index = 'ITEMINDEX' then
    FComboBox.ItemIndex := Value
  else if Index = 'STYLE' then
    FComboBox.Style := Value;
end;

function TRMComboBoxControl.GetPropValue(Index: string): Variant;
begin
  Index := AnsiUpperCase(Index);
  Result := inherited GetPropValue(Index);
  if Result <> Null then Exit;
  if Index = 'ITEMINDEX' then
    Result := FComboBox.ItemIndex
  else if Index = 'STYLE' then
    Result := FComboBox.Style
  else if Index = 'TEXT' then
  begin
    Result := FComboBox.Text;
    if (FComboBox.Style = csOwnerDrawFixed) and (Pos(';', Result) <> 0) then
      Result := Trim(Copy(Result, Pos(';', Result) + 1, 255));
  end
  else if Index = 'ITEMS.COUNT' then
    Result := FComboBox.Items.Count
end;

function TRMComboBoxControl.DoMethod(const MethodName: string; Par1, Par2, Par3: Variant): Variant;
begin
  Result := inherited DoMethod(MethodName, Par1, Par2, Par3);
  if Result = Null then
    Result := LinesMethod(FComboBox.Items, MethodName, 'ITEMS', Par1, Par2, Par3);
end;

procedure TRMComboBoxControl.LoadFromStream(Stream: TStream);
begin
  inherited LoadFromStream(Stream);
  RMReadMemo(Stream, FComboBox.Items);
  if RMVersion >= 27 then
    Prop['Style'] := RMReadByte(Stream);
end;

procedure TRMComboBoxControl.SaveToStream(Stream: TStream);
begin
  LVersion := 0;
  inherited SaveToStream(Stream);
  RMWriteMemo(Stream, FComboBox.Items);
  RMWriteByte(Stream, Prop['Style']);
end;

procedure TRMComboBoxControl.ComboBoxDrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  ComboBox: TComboBox;
  s: string;
begin
  ComboBox := Control as TComboBox;
  with ComboBox.Canvas do
  begin
    FillRect(Rect);
    s := ComboBox.Items[Index];
    if Pos(';', s) <> 0 then
      s := Copy(s, 1, Pos(';', s) - 1);
    TextOut(Rect.Left + 2, Rect.Top + 1, s);
  end;
end;

procedure TRMComboBoxControl.LinesEditor(Sender: TObject);
begin
  with TRMLinesEditorForm.Create(nil) do
  begin
    M1.Lines := FComboBox.Items;
    if (ShowModal = mrOk) and ((Restrictions and RMrfDontModify) = 0) then
    begin
      RMDesigner.BeforeChange;
      FComboBox.Items := M1.Lines;
      RMDesigner.AfterChange;
    end;
    Free;
  end;
end;

{$IFNDEF Delphi2}
{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}
{ TRMDateEditControl }

constructor TRMDateEditControl.Create;
begin
  inherited Create;
  FDateEdit := TDateTimePicker.Create(nil);
  FDateEdit.Parent := RMDialogForm;
  AssignControl(FDateEdit);
  BaseName := 'DateEdit';
  dx := 145; dy := 21;

  RMConsts['dfShort'] := dfShort;
  RMConsts['dfLong'] := dfLong;
end;

destructor TRMDateEditControl.Destroy;
begin
  FDateEdit.Free;
  inherited Destroy;
end;

procedure TRMDateEditControl.DefineProperties;
begin
  inherited DefineProperties;
  AddProperty('Date', [rmdtDate], nil);
  AddEnumProperty('DateFormat', 'dfShort;dfLong', [dfShort, dfLong]);
end;

procedure TRMDateEditControl.SetPropValue(Index: string; Value: Variant);
begin
  inherited SetPropValue(Index, Value);
  Index := AnsiUpperCase(Index);
  if Index = 'DATE' then
    FDateEdit.Date := Value
  else if Index = 'DATEFORMAT' then
    FDateEdit.DateFormat := Value;
end;

function TRMDateEditControl.GetPropValue(Index: string): Variant;
begin
  Index := AnsiUpperCase(Index);
  Result := inherited GetPropValue(Index);
  if Result <> Null then Exit;
  if Index = 'DATE' then
    Result := FDateEdit.Date
  else if Index = 'DATEFORMAT' then
    Result := FDateEdit.DateFormat;
end;

procedure TRMDateEditControl.LoadFromStream(Stream: TStream);
var
  lDateType: string;
begin
  inherited LoadFromStream(Stream);
  if RMVersion >= 29 then
    lDateType := RMReadString(Stream);
  if AnsiCompareStr('WINDOWS', lDateType) = 0 then
  begin
    Prop['DateFormat'] := RMReadByte(Stream);
  end
  else
  begin
    RMReadByte(Stream);
    RMReadByte(Stream);
    RMReadByte(Stream);
  end;
  if RMVersion >= 30 then
    Prop['Date'] := RMReadFloat(Stream);
end;

procedure TRMDateEditControl.SaveToStream(Stream: TStream);
begin
  LVersion := 0;
  inherited SaveToStream(Stream);
  RMWriteString(Stream, 'WINDOWS');
  RMWriteByte(Stream, Prop['DateFormat']);
  RMWriteFloat(Stream, Prop['Date']);
end;
{$ENDIF}

{$IFDEF RX}
{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}
{ TRMRXDateEditControl }

constructor TRMRXDateEditControl.Create;
begin
  inherited Create;
  FDateEdit := TDateEdit.Create(nil);
  FDateEdit.Parent := RMDialogForm;
  FDateEdit.ButtonWidth := 19;
  AssignControl(FDateEdit);
  BaseName := 'DateEdit';
  dx := 145; dy := 21;

  RMConsts['swMon'] := Mon;
  RMConsts['swSun'] := Sun;
  RMConsts['dyDefault'] := dyDefault;
  RMConsts['dyFour'] := dyFour;
  RMConsts['dyTwo'] := dyTwo;
end;

destructor TRMRXDateEditControl.Destroy;
begin
  FDateEdit.Free;
  inherited Destroy;
end;

procedure TRMRXDateEditControl.DefineProperties;
begin
  inherited DefineProperties;
  AddProperty('Date', [], nil);
  AddEnumProperty('ClickKey', RMGetShortCuts, [Null]);
  AddEnumProperty('StartOfWeek', 'swMon;swSun', [Mon, Sun]);
  AddEnumProperty('YearDigits', 'dyDefault;dyFour;dyTwo', [dyDefault, dyFour, dyTwo]);
  AddProperty('Text', [], nil);
end;

procedure TRMRXDateEditControl.SetPropValue(Index: string; Value: Variant);
begin
  inherited SetPropValue(Index, Value);
  Index := AnsiUpperCase(Index);
  if Index = 'CLICKKEY' then
    FDateEdit.ClickKey := TextToShortCut(Value)
  else if Index = 'DATE' then
    FDateEdit.Date := Value
  else if Index = 'STARTOFWEEK' then
    FDateEdit.StartOfWeek := Value
  else if Index = 'TEXT' then
    FDateEdit.Text := Value
  else if Index = 'YEARDIGITS' then
    FDateEdit.YearDigits := Value
end;

function TRMRXDateEditControl.GetPropValue(Index: string): Variant;
begin
  Index := AnsiUpperCase(Index);
  Result := inherited GetPropValue(Index);
  if Result <> Null then Exit;
  if Index = 'CLICKKEY' then
    Result := ShortCutToText(FDateEdit.ClickKey)
  else if Index = 'DATE' then
    Result := FDateEdit.Date
  else if Index = 'TEXT' then
    Result := FDateEdit.Text
  else if Index = 'STARTOFWEEK' then
    Result := FDateEdit.StartOfWeek
  else if Index = 'YEARDIGITS' then
    Result := FDateEdit.YearDigits
end;

procedure TRMRXDateEditControl.LoadFromStream(Stream: TStream);
begin
  inherited LoadFromStream(Stream);
  Prop['StartOfWeek'] := RMReadByte(Stream);
  Prop['YearDigits'] := RMReadByte(Stream);
  FDateEdit.ClickKey := RMReadByte(Stream);
  Prop['Date'] := RMReadFloat(Stream);
end;

procedure TRMRXDateEditControl.SaveToStream(Stream: TStream);
begin
  LVersion := 0;
  inherited SaveToStream(Stream);
  RMWriteByte(Stream, Prop['StartOfWeek']);
  RMWriteByte(Stream, Prop['YearDigits']);
  RMWriteByte(Stream, FDateEdit.ClickKey);
  RMWriteFloat(Stream, Prop['Date']);
end;
{$ENDIF}

initialization
  RMRegisterControl(TRMLabelControl, 'RM_LABELCONTROL', RMLoadStr(SInsertLabel));
  RMRegisterControl(TRMEditControl, 'RM_EDITCONTROL', RMLoadStr(SInsertEdit));
  RMRegisterControl(TRMMemoControl, 'RM_MEMOCONTROL', RMLoadStr(SInsertMemo));
  RMRegisterControl(TRMButtonControl, 'RM_BUTTONCONTROL', RMLoadStr(SInsertButton));
  RMRegisterControl(TRMCheckBoxControl, 'RM_CHECKBOXCONTROL', RMLoadStr(SInsertCheckBox));
  RMRegisterControl(TRMRadioButtonControl, 'RM_RADIOBUTTONCONTROL', RMLoadStr(SInsertRadioButton));
  RMRegisterControl(TRMListBoxControl, 'RM_LISTBOXCONTROL', RMLoadStr(SInsertListBox));
  RMRegisterControl(TRMComboBoxControl, 'RM_COMBOBOXCONTROL', RMLoadStr(SInsertComboBox));
{$IFNDEF Delhi2}
  RMRegisterControl(TRMDateEditControl, 'RM_DATEEDITCONTROL', RMLoadStr(SInsertDateEdit));
{$ENDIF}
{$IFDEF RX}
  RMRegisterControl(TRMRXDateEditControl, 'RM_RXDATEEDITCONTROL', RMLoadStr(SInsertDateEdit));
{$ENDIF}

finalization

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -