📄 osgrideditor.pas
字号:
procedure RunTimeEditor(aGrid : TtsBaseGrid);
var i : Integer;
begin
srcFieldNames := TStringList.Create;
Screen.Cursor := crHourglass;
try
SourceGrid := aGrid;
fmOsGridEditor := TfmOsGridEditor.Create(Application);
except
Screen.Cursor := crDefault;
fmOsGridEditor.Free;
fmOsGridEditor := nil;
raise;
end;
try
if (SourceGrid is TtsDbGrid) then
begin
if (TtsDbGrid(SourceGrid).DataSource <> Nil) then
begin
if TtsDbGrid(SourceGrid).DataSource.DataSet = Nil then
raise Exception.Create('Unable to open TopGrid editor - no Dataset is associated with the DataSource!');
for i := 0 to TtsDbGrid(SourceGrid).DataSource.DataSet.FieldCount - 1 do
srcFieldNames.Add(TtsDbGrid(SourceGrid).DataSource.DataSet.Fields.Fields[i].FieldName);
end;
end;
fmOsGridEditor.ShowModal;
if (not SaveResult) and
(fmOsGridEditor.tbSave.Enabled) and
(MessageDlg('You have unapplied changes - Apply them?', mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
ApplyChanges;
finally
srcFieldNames.Free;
srcFieldNames := Nil;
fmOsGridEditor.Free;
fmOsGridEditor := Nil;
Screen.Cursor := crDefault;
end;
end;
procedure ApplyChanges;
begin
TtsBaseGrid_(demoGrid).InDesignMode := True;
if fmOsGridEditor.FColumnsChanged then
begin
if (SourceGrid is TtsDbGrid) then
TtsDbGrid(SourceGrid).FieldState := fsCustomized;
end;
TtsBaseGrid_(SourceGrid).InDesignMode := True;
CustomAssign(SourceGrid, demoGrid);
if SourceGrid is TtsDbGrid then
begin
CustomColumnDbAssign(TtsDbGrid(SourceGrid), TtsDbGrid(demoGrid));
if (fmOsGridEditor.FColumnsChanged) and
(SourceGrid is TtsDbGrid) then
TtsDbGrid(SourceGrid).FieldState := fsCustomized;
end
else
begin
CustomColumnAssign(TtsGrid(SourceGrid), TtsGrid(demoGrid));
CustomRowAssign(TtsGrid(SourceGrid), TtsGrid(demoGrid));
CustomCellAssign(TtsGrid(SourceGrid), TtsGrid(demoGrid));
end;
end;
procedure CustomRowAssign(tgtGrid, srcGrid : TtsGrid);
var iRow, srcRow : Integer;
begin
tgtGrid.ResetRowProperties(tsAllProperties);
for iRow := 1 to srcGrid.Rows do
begin
srcRow := srcGrid.DataRownr[iRow];
tgtGrid.RowButtonType[iRow] := srcGrid.RowButtonType[srcRow];
tgtGrid.RowControlType[iRow] := srcGrid.RowControlType[srcRow];
tgtGrid.RowDateTimeDef[iRow] := srcGrid.RowDateTimeDef[srcRow];
tgtGrid.RowColor[iRow] := srcGrid.RowColor[srcRow];
tgtGrid.RowParentFont[iRow] := srcGrid.RowParentFont[srcRow];
if srcGrid.RowFont[srcRow] = Nil then
tgtGrid.ResetRowFont(iRow)
else
begin
tgtGrid.AssignRowFont(iRow);
tgtGrid.RowFont[iRow].Assign(srcGrid.RowFont[srcRow]);
end;
tgtGrid.RowHeight[iRow] := srcGrid.RowHeight[srcRow];
tgtGrid.RowIs3D[iRow] := srcGrid.RowIs3D[srcRow];
tgtGrid.RowVisible[iRow] := srcGrid.RowVisible[srcRow];
tgtGrid.RowReadOnly[iRow] := srcGrid.RowReadOnly[srcRow];
tgtGrid.RowMaskName[iRow] := srcGrid.RowMaskName[srcRow];
if srcGrid.RowControlType[srcRow] = ctPicture then
begin
tgtGrid.RowCenterPicture[iRow] := srcGrid.RowCenterPicture[srcRow];
tgtGrid.RowStretchPicture[iRow] := srcGrid.RowStretchPicture[srcRow];
tgtGrid.RowKeepAspectRatio[iRow] := srcGrid.RowKeepAspectRatio[srcRow];
tgtGrid.RowShrinkPicture[iRow] := srcGrid.RowShrinkPicture[srcRow];
end
else if (srcGrid.RowControlType[srcRow] in [ctText, ctDefault]) then
begin
tgtGrid.RowHorzAlignment[iRow] := srcGrid.RowHorzAlignment[srcRow];
tgtGrid.RowVertAlignment[iRow] := srcGrid.RowVertAlignment[srcRow];
tgtGrid.RowWordWrap[iRow] := srcGrid.RowWordWrap[srcRow];
end;
if srcGrid.RowButtonType[srcRow] = btCombo then
begin
tgtGrid.RowParentCombo[iRow] := srcGrid.RowParentCombo[srcRow];
tgtGrid.RowDropDownStyle[iRow] := srcGrid.RowDropDownStyle[srcRow];
end
else if (srcGrid.RowButtonType[iRow] = btVertSpin) or
(srcGrid.RowButtonType[iRow] = btHorzSpin) then
begin
tgtGrid.RowSpinIncrement[iRow] := srcGrid.RowSpinIncrement[srcRow];
end;
end;
end;
procedure CustomCellAssign(tgtGrid, srcGrid : TtsGrid);
var iRow, iCol, jCol, dataCol, dataRow : Integer;
begin
tgtGrid.ResetCellProperties(tsAllProperties);
for iRow := 1 to srcGrid.Rows do
begin
for iCol := 1 to srcGrid.Cols do
begin
tgtGrid.CellButtonType[iCol, iRow] := srcGrid.CellButtonType[iCol, iRow];
tgtGrid.CellControlType[iCol, iRow] := srcGrid.CellControlType[iCol, iRow];
tgtGrid.CellDateTimeDef[iCol, iRow] := srcGrid.CellDateTimeDef[iCol, iRow];
tgtGrid.CellColor[iCol, iRow] := srcGrid.CellColor[iCol, iRow];
tgtGrid.CellParentFont[iCol, iRow] := srcGrid.CellParentFont[iCol, iRow];
if srcGrid.CellFont[iCol, iRow] = Nil then
tgtGrid.ResetCellFont(iCol, iRow)
else
begin
tgtGrid.AssignCellFont(iCol, iRow);
tgtGrid.CellFont[iCol, iRow].Assign(srcGrid.CellFont[iCol, iRow]);
end;
tgtGrid.CellIs3D[iCol, iRow] := srcGrid.CellIs3D[iCol, iRow];
tgtGrid.CellReadOnly[iCol, iRow] := srcGrid.CellReadOnly[iCol, iRow];
tgtGrid.CellMaskName[iCol, iRow] := srcGrid.CellMaskName[iCol, iRow];
if srcGrid.CellControlType[iCol, iRow] = ctPicture then
begin
tgtGrid.CellCenterPicture[iCol, iRow] := srcGrid.CellCenterPicture[iCol, iRow];
tgtGrid.CellStretchPicture[iCol, iRow] := srcGrid.CellStretchPicture[iCol, iRow];
tgtGrid.CellKeepAspectRatio[iCol, iRow] := srcGrid.CellKeepAspectRatio[iCol, iRow];
tgtGrid.CellShrinkPicture[iCol, iRow] := srcGrid.CellShrinkPicture[iCol, iRow];
end
else if srcGrid.CellControlType[iCol, iRow] in [ctText, ctDefault] then
begin
tgtGrid.CellHorzAlignment[iCol, iRow] := srcGrid.CellHorzAlignment[iCol, iRow];
tgtGrid.CellVertAlignment[iCol, iRow] := srcGrid.CellVertAlignment[iCol, iRow];
tgtGrid.CellWordWrap[iCol, iRow] := srcGrid.CellWordWrap[iCol, iRow];
end;
if srcGrid.CellButtonType[iCol, iRow] = btCombo then
begin
tgtGrid.CellParentCombo[iCol, iRow] := srcGrid.CellParentCombo[iCol, iRow];
tgtGrid.CellDropDownStyle[iCol, iRow] := srcGrid.CellDropDownStyle[iCol, iRow];
end
else if (srcGrid.CellButtonType[iCol, iRow] = btVertSpin) or
(srcGrid.CellButtonType[iCol, iRow] = btHorzSpin) then
begin
tgtGrid.CellSpinIncrement[iCol, iRow] := srcGrid.CellSpinIncrement[iCol, iRow];
tgtGrid.CellSpinOptions[iCol, iRow] := srcGrid.CellSpinOptions[iCol, iRow];
end;
if srcGrid.StoreData then
tgtGrid.Cell[iCol, iRow] := srcGrid.Cell[iCol, iRow];
if tgtGrid.CellButtonType[iCol, iRow] = btCombo then
begin
tgtGrid.AssignCellCombo(iCol, iRow);
tgtGrid.CellCombo[iCol, iRow].Assign(srcGrid.CellCombo[iCol, iRow]);
for jCol := 1 to srcGrid.CellCombo[iCol, iRow].Grid.Cols do
tgtGrid.CellCombo[iCol, iRow].Grid.Col[jCol].Assign(srcGrid.CellCombo[iCol, iRow].Grid.Col[jCol]);
if srcGrid.CellCombo[iCol, iRow].Grid.StoreData then
for dataRow := 1 to srcGrid.CellCombo[iCol, iRow].Grid.Rows do
for dataCol := 1 to srcGrid.CellCombo[iCol, iRow].Grid.Cols do
tgtGrid.CellCombo[iCol, iRow].Grid.Cell[dataCol, dataRow] := srcGrid.CellCombo[iCol, iRow].Grid.Cell[dataCol, dataRow];
end;
end;
end;
end;
procedure CustomColumnAssign(tgtGrid, srcGrid : TtsGrid);
var
PropertyIndex, PropertyCount, iCol, jCol, dataCol, dataRow : Integer;
PropList : TPropList;
sName : String;
aCol : TtsCol;
Value : Variant;
Columns : TStringList;
begin
tgtGrid.EnableRedraw := False;
Columns := TStringList.Create;
try
tgtGrid.Cols := 0;
tgtGrid.Cols := srcGrid.Cols;
if tgtGrid.Cols = 0 then exit;
PropertyCount := GetPropList(srcGrid.Col[1].ClassInfo, tkProperties, @PropList);
for iCol := 1 to srcGrid.Cols do
Columns.AddObject(Format('%8.7d', [srcGrid.Col[iCol].DisplayCol]), srcGrid.Col[iCol]);
Columns.Sort;
for iCol := 1 to srcGrid.Cols do
begin
aCol := TtsCol(Columns.Objects[iCol-1]);
for PropertyIndex := 0 to PropertyCount - 1 do
begin
sName := PropList[PropertyIndex].Name;
if aCol.Tag = 1 then
tgtGrid.Col[iCol].Visible := False;
if (AnsiCompareText(sName, 'Font') = 0) then
begin
if (aCol.ParentFont = False) then
begin
tgtGrid.Col[iCol].ParentFont := False;
tgtGrid.Col[iCol].Font.Assign(aCol.Font);
end
else Continue;
end
else if (AnsiCompareText(sName, 'HeadingFont') = 0) then
begin
if (aCol.HeadingParentFont = False) then
begin
tgtGrid.Col[iCol].HeadingParentFont := False;
tgtGrid.Col[iCol].HeadingFont.Assign(aCol.HeadingFont);
end
else Continue;
end
else if (AnsiCompareText(sName, 'DateTimeDef') = 0) then
tgtGrid.Col[iCol].DateTimeDef := aCol.DateTimeDef
else if (sName <> 'ComboDatasource') and
//(sName <> 'DateTimeDef') and
(sName <> 'DisplayCol') then
try
Value := GetPropValue(aCol, sName, False);
if VarType(Value) <> varEmpty then
begin
if VarType(Value) = varBoolean then
SetPropValue(tgtGrid.Col[iCol], sName, BooleanToStr(Value))
else
SetPropValue(tgtGrid.Col[iCol], sName, Value);
end;
except on E:Exception do
//ShowMessage('Error setting col property ' + sName);
end;
end; // Property assignments...
// Now Combo properties if present...
if aCol.ButtonType = btCombo then
begin
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;
if srcGrid.StoreData then
for dataRow := 1 to srcGrid.Rows do
for dataCol := 1 to srcGrid.Cols do
tgtGrid.Cell[dataCol, dataRow] := srcGrid.Cell[dataCol, dataRow];
finally
Columns.Free;
tgtGrid.EnableRedraw := True;
tgtGrid.Invalidate;
end;
end;
procedure CustomColumnDbAssign(tgtGrid, srcGrid : TtsDbGrid);
var
PropertyIndex, PropertyCount, iCol, jCol, dataCol, dataRow : Integer;
PropList : TPropList;
sName : String;
Value : Variant;
aCol : TtsDbCol;
Columns : TStringList;
begin
tgtGrid.EnableRedraw := False;
Columns := TStringList.Create;
try
tgtGrid.Cols := 0;
tgtGrid.Cols := srcGrid.Cols;
if tgtGrid.Cols = 0 then exit;
PropertyCount := GetPropList(srcGrid.Col[1].ClassInfo, tkProperties, @PropList);
// Load the columns by displaycol to sort by the displayCol...
for iCol := 1 to srcGrid.Cols do
Columns.AddObject(Format('%8.7d', [srcGrid.Col[iCol].DisplayCol]), srcGrid.Col[iCol]);
Columns.Sort;
for iCol := 1 to srcGrid.Cols do
begin
aCol := TtsDbCol(Columns.Objects[iCol-1]);
for PropertyIndex := 0 to PropertyCount - 1 do
begin
sName := PropList[PropertyIndex].Name;
if aCol.Tag = 1 then
tgtGrid.Col[iCol].Visible := False;
if (AnsiCompareText(sName, 'Font') = 0) then
begin
if (aCol.ParentFont = False) then
begin
tgtGrid.Col[iCol].ParentFont := False;
tgtGrid.Col[iCol].Font.Assign(aCol.Font);
end
else Continue;
end
else if (AnsiCompareText(sName, 'DateTimeDef') = 0) then
tgtGrid.Col[iCol].DateTimeDef := aCol.DateTimeDef
else if (AnsiCompareText(sName, 'HeadingFont') = 0) then
begin
if (aCol.HeadingParentFont = False) then
begin
tgtGrid.Col[iCol].HeadingParentFont := False;
tgtGrid.Col[iCol].HeadingFont.Assign(aCol.HeadingFont);
end
else Continue;
end
else if (sName <> 'ComboDatasource') and (sName <> 'DateTimeDef') and
(sName <> 'DisplayCol') then
try
Value := GetPropValue(aCol, sName, False);
if VarType(Value) <> varEmpty then
begin
if VarType(Value) = varBoolean then
SetPropValue(tgtGrid.Col[iCol], sName, BooleanToStr(Value))
else
SetPropValue(tgtGrid.Col[iCol], sName, Value);
end;
except on E:Exception do
//ShowMessage('Error setting col property ' + sName);
end;
end; // Property assignments...
// Now Combo properties if present...
if aCol.ButtonType = btCombo then
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -