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

📄 osgrideditor.pas

📁 企业进销存管理系统
💻 PAS
📖 第 1 页 / 共 5 页
字号:
        if (aCol.Combo <> Nil) then
        begin
          tgtGrid.Col[iCol].AssignCombo;
          tgtGrid.Col[iCol].Combo.Assign(aCol.Combo);
          for jCol := 1 to aCol.Combo.Grid.Cols do
            tgtGrid.Col[iCol].Combo.Grid.Col[jCol].Assign(aCol.Combo.Grid.Col[jCol]);
          if aCol.Combo.Grid.StoreData then
             for dataRow := 1 to aCol.Combo.Grid.Rows do
                for dataCol := 1 to aCol.Combo.Grid.Cols do
                  tgtGrid.Col[iCol].Combo.Grid.Cell[dataCol, dataRow] := aCol.Combo.Grid.Cell[dataCol, dataRow];
        end;
      end;
    end;
  finally
    Columns.Free;
    tgtGrid.EnableRedraw := True;
    tgtGrid.Invalidate;
  end;
end;

procedure CustomAssign(tgtGrid, srcGrid : TtsBaseGrid);
var
  PropertyIndex, PropertyCount : Integer;
  PropList      : TPropList;
  sName : String;
  Value : Variant;
begin
  PropertyCount := GetPropList(srcGrid.ClassInfo, tkProperties, @PropList);
  for PropertyIndex := 0 to PropertyCount -1 do
  begin
    sName := PropList[PropertyIndex].Name;
    if (sName = 'Font') then
      TtsBaseGrid_(tgtGrid).Font.Assign(TtsBaseGrid_(srcGrid).Font)
    else if (sName = 'HeadingFont') then
      TtsBaseGrid_(tgtGrid).HeadingFont.Assign(TtsBaseGrid_(srcGrid).HeadingFont)
    else if (sName = 'ImageList') then
      TtsBaseGrid_(tgtGrid).ImageList := TtsBaseGrid_(srcGrid).ImageList
    else if (sName <> 'Align') and (sName <> 'Top') and
       (sName <> 'Left') and (sName <> 'Height') and
       (sName <> 'Anchors') and (sName <> 'Constraints') and
       (sName <> 'Width') and //(sName <> 'Cols') and
       (sName <> 'DataSource') and (sName <> 'DateTimeDef') and
       (sName <> 'Enabled') and (sName <> 'Name') and
       (sName <> 'PopupMenu') and (sName <> 'Name') and
       (sName <> 'ImageList') and (sName <> 'MaskDefs') and
       (sName <> 'GridReport') then
    begin
      try
        Value := GetPropValue(srcGrid, sName, False);
        if VarType(Value) <> varEmpty then
        begin
          if VarType(Value) = varBoolean then
             SetPropValue(tgtGrid, sName, BooleanToStr(Value))
          else if (sName = 'TosXMLExport') then
             TtsBaseGrid_(tgtGrid).XMLExport := TtsBaseGrid_(srcGrid).XMLExport
          else
             SetPropValue(tgtGrid, sName, Value);
        end;
      except on E:Exception do
        //ShowMessage('Error assigning property ' + sName);
      end;
    end;
  end;
end;

function  BooleanToStr(Value : Boolean) : String;
begin
  if Value then
     Result := 'True'
  else
     Result := 'False';
end;

procedure TfmOsGridEditor.SetTargetGrid(Value : TtsBaseGrid);
{$IFDEF rtTest}
var i : integer;
{$ENDIF}
begin
  //ShowMessage('SetTargetGrid');
  FTargetGrid := Value;
  if (FTargetGrid <> Nil) and
     (FTargetGrid is TtsDbGrid) then
  begin
    sampleDbGrid.BringToFront;
    demoGrid := sampleDbGrid;
    CustomAssign(sampleDbGrid, TtsDbGrid(FTargetGrid));
    tsRowProperties.TabVisible := False;
    tsCellProperties.TabVisible := False;
    sampleDbGrid.PopupMenu := pmOptions;
    sampleDbGrid.Align := alClient;
    //sampleDbGrid.ProvideGridMenu := False;
  end
  else
  begin
    sampleDbGrid.DataSource := Nil;
    sampleGrid.BringToFront;
    demoGrid := sampleGrid;
    CustomAssign(sampleGrid, TtsGrid(FTargetGrid));
    CustomColumnAssign(sampleGrid, TtsGrid(FTargetGrid));
    CustomRowAssign(sampleGrid, TtsGrid(FTargetGrid));
    CustomCellAssign(sampleGrid, TtsGrid(FTargetGrid));
    //sampleGrid.ProvideGridMenu := False;
    sampleGrid.Align := alClient;
    sampleGrid.PopupMenu := pmOptions;
  end;

  sbStatus.Panels[0].Text := 'Source: ' + Value.Name;
{$IFDEF rtTest}
  if (SourceGrid is TtsDbGrid) and
     (TtsDbGrid(SourceGrid).DataSource <> Nil) then
  begin
     srcFieldNames := TStringList.Create;
     for i := 0 to TtsDbGrid(SourceGrid).DataSource.DataSet.FieldCount - 1 do
        srcFieldNames.Add(TtsDbGrid(SourceGrid).DataSource.DataSet.Fields.Fields[i].FieldName);
  end;
{$ENDIF}
end;

procedure TfmOsGridEditor.Initialize;
var theCol : TtsCol;
    i : Integer;
begin
  FBinding := True;
  FColumnsChanged := False;
  miSortedFieldList.Checked := GetFieldSort;
  if SourceGrid <> Nil then
     TargetGrid := SourceGrid;
  //ShowMessage('Initialize');
  try
  veEditor.EnableRedraw := False;
  veEditor.EnablePaint := False;
  try
    veEditor.Rows := 0;
    theCol := veEditor.Col[1];
    theCol.ReadOnly := True;
    theCol.Heading := 'Property';
    sleep(50);
    theCol := veEditor.Col[2];
    theCol.Heading := 'Value';
  finally
    veEditor.EnableRedraw := True;
    veEditor.EnablePaint := True;
    veEditor.Invalidate;
  end;
  veColEditor.EnableRedraw := False;
  veColEditor.EnablePaint := False;
  try
    veColEditor.Rows := 0;
    sleep(50);
    theCol := veColEditor.Col[1];
    theCol.Heading := 'Key';
    theCol.ReadOnly := True;
    sleep(50);
    theCol := veColEditor.Col[2];
    theCol.Heading := 'Value';
  finally
    veColEditor.EnableRedraw := True;
    veColEditor.EnablePaint := True;
    veColEditor.Invalidate;
  end;

  finally
    //ShowMessage('SetupPropertyLists');
    SetupPropertyLists;
    EnumList := TStringList.Create;
    GridModifiedProperties := TStringList.Create;
    GridCustomProperties := TStringList.Create;
    LoadCustomGridProperties;
    GridModifiedProperties.Duplicates := dupIgnore;
    ColModifiedProperties := TStringList.Create;
    ColModifiedProperties.Duplicates := dupIgnore;
    cbPropertyView.ItemIndex := cbPropertyView.Items.IndexOf(GridView);
    if cbPropertyView.ItemIndex = -1 then
       cbPropertyView.ItemIndex := 0;
    cbColPropertyView.ItemIndex := cbColPropertyView.Items.IndexOf(ColumnView);
    if cbColPropertyView.ItemIndex = -1 then
       cbColPropertyView.ItemIndex := 0;
    //ShowMessage('RefreshGridProperties');
    RefreshGridProperties;
    comboDataBookmarks := TStringList.Create;
    LoadFieldNames;
    LoadSystemMasks;
    AppendCustomMasks;
    AppendTtsMaskMasks;
    EnsureCombos;
    ResetWindowState;
    
    FBinding := False;
    if GetGridCols > 0 then
       SelectedCol := 1;
    AdjustCommonProperties;
    for i := 1 to GetGridCols do
      if not GetGridCol(i).Visible then
      begin
        GetGridCol(i).Visible := True;
        GetGridCol(i).Tag := 1;
        GetGridCol(i).HeadingColor := clWindow;
      end;
    tbSave.Enabled := False;
  end;
  AdjustToolbar;
end;

procedure TfmOsGridEditor.FormCreate(Sender: TObject);
begin
  FStartup := True;
  FBinding := True;
{$IFDEF rtTest}
  //SourceGrid := gdTest;
  //demoGrid := sampleDbGrid;
{$ELSE}
  //ShowMessage('Source Grid is Set');
  demoGrid := SourceGrid;
{$ENDIF}
  demoGrid := SourceGrid;
  if demoGrid is TtsDbGrid then
     sampleDbGrid.DataSource := TtsDbGrid(demoGrid).DataSource;
  ResetWindowState;
end;

procedure TfmOsGridEditor.FormActivate(Sender: TObject);
begin
  if Self.Tag = 0 then
     Initialize;
  Self.Tag := 1;
end;

procedure TfmOsGridEditor.FormDestroy(Sender: TObject);
var i : integer;
begin
  //ShowMessage('FormDestroy');
  SaveWindowState;
  
  ControlProperties.Free;
  BasicProperties.Free;
  VCLProperties.Free;
  DataProperties.Free;
  ColControlProperties.Free;
  ColBasicProperties.Free;
  ColCustomProperties.Free;
  EnumList.Free;
  GridModifiedProperties.Free;
  GridCustomProperties.Free;
  ColModifiedProperties.Free;
  comboDataBookmarks.Free;
  comboGridProperties.Free;
  ClearFieldNames;
  for i := 0 to cbMask.Items.Count - 1 do
    TosMaskEntry(cbMask.Items.Objects[i]).Free;

end;

procedure TfmOsGridEditor.ClearFieldNames;
var i : Integer;
begin
  if Fieldnames <> Nil then
  begin
    for i := 0 to FieldNames.Count - 1 do
      FieldNames.Objects[i].Free;
    FieldNames.Free;
    FieldNames := Nil;
  end;
end;

procedure TfmOsGridEditor.Apply;
begin
  SaveResult := True;
  ApplyChanges;
  //FTargetGrid.Assign(demoGrid);
{$IFNDEF rtTest}
 // Designer.Modified;
{$ENDIF}
end;

function TfmOsGridEditor.GetGridMode : TtsGridMode;
begin
  if demoGrid is TtsDbGrid then Result := TtsDbGrid(demoGrid).GridMode
  else Result := TtsGrid(demoGrid).GridMode;
end;

function TfmOsGridEditor.GetGridFont : TFont;
begin
  if demoGrid is TtsDbGrid then Result := TtsDbGrid(demoGrid).Font
  else Result := TtsGrid(demoGrid).Font;
end;

function TfmOsGridEditor.GetGridHeadingFont : TFont;
begin
  if demoGrid is TtsDbGrid then Result := TtsDbGrid(demoGrid).HeadingFont
  else Result := TtsGrid(demoGrid).HeadingFont;
end;

function TfmOsGridEditor.GetGridColor : TColor;
begin
  if demoGrid is TtsDbGrid then Result := TtsDbGrid(demoGrid).Color
  else Result := TtsGrid(demoGrid).Color;
end;

function TfmOsGridEditor.GetGridHeadingColor : TColor;
begin
  if demoGrid is TtsDbGrid then Result := TtsDbGrid(demoGrid).HeadingColor
  else Result := TtsGrid(demoGrid).HeadingColor;
end;

{function TfmOsGridEditor.GetGridDisplayColnr(iCol : Integer) : Integer;
begin
  if demoGrid is TtsDbGrid then Result := TtsDbGrid(demoGrid).DisplayColnr[iCol]
  else Result := TtsGrid(demoGrid).DisplayColnr[iCol];
end;}

function TfmOsGridEditor.GetGridDataColnr(iDisplayCol : Integer) : Integer;
begin
  if demoGrid is TtsDbGrid then Result := TtsDbGrid(demoGrid).DataColnr[iDisplayCol]
  else Result := TtsGrid(demoGrid).DataColnr[iDisplayCol];
end;

function TfmOsGridEditor.GetGridCol(iCol : Integer) : TtsCol;
begin
  if demoGrid is TtsDbGrid then Result := TtsDbGrid(demoGrid).Col[iCol]
  else Result := TtsGrid(demoGrid).Col[iCol];
end;

function TfmOsGridEditor.GetGridCurrentDataRow : Variant;
begin
  if demoGrid is TtsDbGrid then Result := TtsDbGrid(demoGrid).CurrentDataRow
  else Result := TtsGrid(DemoGrid).CurrentDataRow;
end;

function TfmOsGridEditor.GetGridFixedColCount : Integer;
begin
  if demoGrid is TtsDbGrid then Result := TtsDbGrid(demoGrid).FixedColCount
  else Result := TtsGrid(DemoGrid).FixedColCount;
end;

fun

⌨️ 快捷键说明

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