📄 cxvgriddxinspconverter.pas
字号:
public
constructor CreateFor(AComponent: TObject);
procedure CreateVisibleRows(AStream: TStream; AConverter: TcxCustomDXInspConverter);
procedure DefineProperty(const Name: string; ReadData: TReaderProc;
WriteData: TWriterProc; HasData: Boolean); override;
procedure DefineBinaryProperty(const Name: string; AReadData, AWriteData: TStreamProc; HasData: Boolean); override;
procedure FlushBuffer; override;
property HasData: Boolean read FHasData;
property ReadDataProc: TStreamProc read FReadDataProc;
property WriteDataProc: TStreamProc read FWriteDataProc;
end;
constructor TcxConverterFiler.CreateFor(AComponent: TObject);
begin
TComponentAccess(AComponent).DefineProperties(Self);
end;
procedure TcxConverterFiler.CreateVisibleRows(AStream: TStream;
AConverter: TcxCustomDXInspConverter);
var
AReader: TcxReader;
I, AItemCount: Integer;
procedure ReadInfo(AcxParentRow: TcxCustomRow);
var
PInfo: PdxRowNodeInfo;
I, ACount, ASize: Integer;
S: string;
begin
ASize := AReader.ReadInteger;
GetMem(PInfo, ASize);
try
AStream.ReadBuffer(PInfo^, ASize);
SetLength(S, PInfo^.StrLen);
AStream.ReadBuffer(S[1], PInfo^.StrLen);
ACount := PInfo^.Count;
AcxParentRow := AConverter.AddRow(AcxParentRow, S);
if AcxParentRow <> nil then
AConverter.FdxRowCache.AddObject(S, AcxParentRow);
for I := 0 to ACount - 1 do
ReadInfo(AcxParentRow);
finally
FreeMem(PInfo, ASize);
end;
end;
procedure ReadExpandedData;
var
PInfo: PdxRowNodeInfo;
I, Index, ACount, ASize: Integer;
S: string;
begin
if AStream.Position = AStream.Size then Exit;
AConverter.Destination.FullCollapse;
ACount := AReader.ReadInteger;
for I := 0 to ACount - 1 do
begin
ASize := AReader.ReadInteger;
GetMem(PInfo, ASize);
try
AStream.ReadBuffer(PInfo^, ASize);
SetLength(S, PInfo^.StrLen);
AStream.ReadBuffer(S[1], PInfo^.StrLen);
Index := AConverter.FdxRowCache.IndexOf(S);
if Index >= 0 then
TcxCustomRow(AConverter.FdxRowCache.Objects[Index]).Expanded := True;
finally
FreeMem(PInfo, ASize);
end;
end;
end;
begin
AReader := TcxReader.Create(AStream);
try
AConverter.Destination.ClearRows;
try
if (AStream.Size > 0) and (AReader.ReadInteger > 0) then
begin
AItemCount := AReader.ReadInteger;
for I := 0 to AItemCount - 1 do
ReadInfo(nil);
ReadExpandedData;
end;
except
AConverter.Destination.ClearRows;
raise;
end;
finally
AReader.Free;
end;
end;
procedure TcxConverterFiler.DefineProperty(const Name: string; ReadData: TReaderProc;
WriteData: TWriterProc; HasData: Boolean);
begin
end;
procedure TcxConverterFiler.DefineBinaryProperty(const Name: string;
AReadData, AWriteData: TStreamProc; HasData: Boolean);
begin
if Name <> 'Data' then Exit;
FHasData := HasData;
FReadDataProc := AReadData;
FWriteDataProc := AWriteData;
end;
procedure TcxConverterFiler.FlushBuffer;
begin
end;
procedure TcxCustomDXInspConverter.ImportCategoryRow(AdxRow: TObject;
AcxRow: TcxCustomRow);
begin
AssignCaptionProperties(AdxRow, TcxCategoryRow(AcxRow).Properties);
end;
procedure TcxCustomDXInspConverter.ImportEditorRow(AdxRow: TObject;
AcxRow: TcxCustomRow);
var
AProperties: TcxCustomEditorRowProperties;
begin
AProperties := TcxCustomEditorRowAccess(AcxRow).Properties;
AssignCaptionProperties(AdxRow, AProperties);
AssignEditorProperties(AdxRow, AProperties);
end;
procedure TcxCustomDXInspConverter.ImportLayout;
var
AFiler: TcxConverterFiler;
AMemStream: TMemoryStream;
begin
AFiler := TcxConverterFiler.CreateFor(Source);
try
if AFiler.HasData then
begin
AMemStream := TMemoryStream.Create;
try
begin
AFiler.WriteDataProc(AMemStream);
AMemStream.Position := 0;
AFiler.CreateVisibleRows(AMemStream, Self);
end;
finally
AMemStream.Free;
end;
end;
finally
AFiler.Free;
end;
end;
procedure TcxCustomDXInspConverter.ImportMultiEditorRow(AdxRow: TObject;
AcxRow: TcxCustomRow);
var
I, AIndex: Integer;
AItems, AItem, AItemRow: TObject;
AMultiEditorRowItem: TcxCollectionItemEditorRowProperties;
begin
if FSeparatorString <> '' then
with TcxCustomMultiEditorRowAccess(AcxRow).Properties do
begin
SeparatorKind := skString;
SeparatorString := FSeparatorString;
end;
AItems := GetClassProperty(AdxRow, 'Items');
if AItems is TCollection then
with TCollection(AItems) do
begin
for I := 0 to Count - 1 do
begin
AItem := Items[I];
AItemRow := GetClassProperty(AItem, 'Row');
if AItemRow <> nil then
begin
AMultiEditorRowItem := CreateMultiEditorRowItem(AcxRow);
AssignCaptionProperties(AItemRow, AMultiEditorRowItem);
AssignEditorProperties(AItemRow, AMultiEditorRowItem);
if (I = 0) and (AMultiEditorRowItem.ImageIndex = -1) then
AMultiEditorRowItem.ImageIndex := GetIntegerProperty(AdxRow, 'ImageIndex');
AMultiEditorRowItem.Width := GetIntegerProperty(AItem, 'Width', 50);
AIndex := FdxRowCache.IndexOf(GetStringProperty(AItemRow, 'Name'));
if AIndex >= 0 then FdxRowCache.Delete(AIndex);
end;
end;
end;
end;
procedure TcxCustomDXInspConverter.ImportRow(AcxRow: TcxCustomRow;
AdxRow: TObject);
var
H: Integer;
begin
H := GetIntegerProperty(AdxRow, 'Height', 17);
if H <> FDefaultRowHeight then
AcxRow.Height := H;
AcxRow.Visible := GetBooleanProperty(AdxRow, 'Visible');
if AcxRow is TcxCategoryRow then
ImportCategoryRow(AdxRow, AcxRow)
else if AcxRow is TcxCustomMultiEditorRow then
ImportMultiEditorRow(AdxRow, AcxRow)
else
ImportEditorRow(AdxRow, AcxRow);
end;
procedure TcxCustomDXInspConverter.ImportRows;
var
I: Integer;
AComponent: TComponent;
begin
// get invisible rows
with Component.Owner do
for I := 0 to ComponentCount - 1 do
begin
AComponent := Components[I];
if InheritsFromEx(AComponent, 'TdxInspectorRow') and
(AComponent.GetParentComponent = Source) then
if not GetBooleanProperty(AComponent, 'Visible', True) then
FdxRowCache.AddObject(AComponent.Name, nil);
end;
// get visible rows
ImportLayout;
for I := 0 to FdxRowCache.Count -1 do
if FdxRowCache.Objects[I] = nil then
FdxRowCache.Objects[I] := AddRow(nil, FdxRowCache[I]);
end;
procedure TcxCustomDXInspConverter.SetRowName(AcxRow: TcxCustomRow);
begin
AcxRow.Name := CreateUniqueName(Destination.Owner, Destination, AcxRow, 'Tcx', '');
end;
function TcxCustomDXInspConverter.GetAccess: TcxCustomVerticalGridAccess;
begin
Result := TcxCustomVerticalGridAccess(inherited Destination);
end;
function TcxCustomDXInspConverter.GetComponent: TComponent;
begin
Result := Source as TComponent;
end;
{ TcxDXInspConverter }
class function TcxDXInspConverter.GetSourceClassName: string;
begin
Result := 'TdxInspector';
end;
procedure TcxDXInspConverter.AssignEditorDataBinding(
AdxRow: TObject; AProperties: TcxCustomEditorRowProperties);
var
Index: Integer;
S: string;
begin
Index := GetConvertorIndex(AdxRow);
if Index < 0 then Exit;
if ConvertorTable[Index].ValueType <> nil then
TcxEditorRowProperties(AProperties).DataBinding.ValueTypeClass :=
ConvertorTable[Index].ValueType;
S := GetStringProperty(AdxRow, 'Text');
if S <> '' then
try
if ConvertorTable[Index].ValueType = TcxDateTimeValueType then
TcxEditorRowProperties(AProperties).Value := StrToDateTime(S)
else
TcxEditorRowProperties(AProperties).Value := S;
except
end;
end;
procedure TcxDXInspConverter.AssignVerticalGridOptions;
var
S: TStringList;
begin
inherited AssignVerticalGridOptions;
S := TStringList.Create;
with Destination do
try
GetSetProperty(Source, 'Options', S);
if S.IndexOf('ioAutoBandCount') >= 0 then
LayoutStyle := ulsBandsView
else
LayoutStyle := ulsSingleRecordView;
OptionsView.AutoScaleBands := False;
OptionsView.CellAutoHeight := S.IndexOf('ioRowAutoHeight') >= 0;
OptionsView.CellEndEllipsis := S.IndexOf('ioDrawEndEllipsis') >= 0;
OptionsBehavior.BandSizing := S.IndexOf('ioBandSizing') >= 0;
OptionsBehavior.HeaderSizing := S.IndexOf('ioColumnSizing') >= 0;
OptionsBehavior.GoToNextCellOnTab := S.IndexOf('ioTabThrough') >= 0;
OptionsBehavior.GoToNextCellOnEnter := S.IndexOf('ioEnterThrough') >= 0;
OptionsBehavior.RowSizing := S.IndexOf('ioRowSizing') >= 0;
OptionsData.Editing := S.IndexOf('ioEditing') >= 0;
finally
S.Free;
end;
end;
function TcxDXInspConverter.CreateMultiEditorRowItem(
AcxRow: TcxCustomRow): TcxCollectionItemEditorRowProperties;
begin
Result := TcxMultiEditorRow(AcxRow).Properties.Editors.Add;
end;
function TcxDXInspConverter.GetRowClassType(
AdxRow: TObject): TcxCustomRowClass;
begin
Result := nil;
if AdxRow = nil then Exit;
if GetBooleanProperty(AdxRow, 'IsCategory') then
Result := TcxCategoryRow
else if SameText(AdxRow.ClassName, 'TdxInspectorComplexRow') then
Result := TcxMultiEditorRow
else
Result := TcxEditorRow;
end;
function TcxDXInspConverter.GetDestination: TcxUnboundVerticalGridAccess;
begin
Result := TcxUnboundVerticalGridAccess(inherited Destination);
end;
{ TcxDXDBInspConverter }
class function TcxDXDBInspConverter.GetSourceClassName: string;
begin
Result := 'TdxDBInspector';
end;
procedure TcxDXDBInspConverter.AssignEditorDataBinding(
AdxRow: TObject; AProperties: TcxCustomEditorRowProperties);
begin
TcxDBVerticalGridItemDataBinding(TcxCustomEditorRowPropertiesAccess(
AProperties).DataBinding).FieldName := GetStringProperty(AdxRow, 'FieldName');
end;
procedure TcxDXDBInspConverter.AssignVerticalGrid;
begin
inherited AssignVerticalGrid;
Destination.DataController.DataSource :=
TDataSource(GetClassProperty(Source, 'DataSource'));
end;
procedure TcxDXDBInspConverter.AssignVerticalGridOptions;
var
S: TStringList;
begin
inherited AssignVerticalGridOptions;
S := TStringList.Create;
with Destination do
try
GetSetProperty(Source, 'Options', S);
if S.IndexOf('dioAutoBandCount') >= 0 then
LayoutStyle := lsBandsView
else
LayoutStyle := lsSingleRecordView;
OptionsView.AutoScaleBands := False;
OptionsView.CellAutoHeight := S.IndexOf('dioRowAutoHeight') >= 0;
OptionsView.CellEndEllipsis := S.IndexOf('dioDrawEndEllipsis') >= 0;
OptionsBehavior.BandSizing := S.IndexOf('dioBandSizing') >= 0;
OptionsBehavior.HeaderSizing := S.IndexOf('dioColumnSizing') >= 0;
OptionsBehavior.GoToNextCellOnTab := S.IndexOf('dioTabThrough') >= 0;
OptionsBehavior.GoToNextCellOnEnter := S.IndexOf('dioEnterThrough') >= 0;
OptionsBehavior.RowSizing := S.IndexOf('dioRowSizing') >= 0;
OptionsData.CancelOnExit := S.IndexOf('dioCancelOnExit') >= 0;
OptionsData.Editing := S.IndexOf('dioEditing') >= 0;
finally
S.Free;
end;
end;
function TcxDXDBInspConverter.CreateMultiEditorRowItem(
AcxRow: TcxCustomRow): TcxCollectionItemEditorRowProperties;
begin
Result := TcxDBMultiEditorRow(AcxRow).Properties.Editors.Add;
end;
function TcxDXDBInspConverter.GetConvertorIndex(AdxRow: TObject): Integer;
var
I: Integer;
begin
Result := -1;
for I := 0 to 17 do
if SameText(AdxRow.ClassName, ConvertorTable[I].DBRowClassName) then
begin
Result := I;
break
end;
end;
function TcxDXDBInspConverter.GetRowClassType(
AdxRow: TObject): TcxCustomRowClass;
begin
Result := nil;
if AdxRow = nil then Exit;
if GetBooleanProperty(AdxRow, 'IsCategory') then
Result := TcxCategoryRow
else if SameText(AdxRow.ClassName, 'TdxInspectorComplexRow') then
Result := TcxDBMultiEditorRow
else
Result := TcxDBEditorRow;
end;
procedure TcxDXDBInspConverter.SetRowName(AcxRow: TcxCustomRow);
begin
if AcxRow is TcxDBEditorRow then
AcxRow.Name := CreateUniqueName(Destination.Owner, Destination, AcxRow,
'Tcx', TcxDBEditorRow(AcxRow).Properties.DataBinding.FieldName)
else
inherited SetRowName(AcxRow);
end;
function TcxDXDBInspConverter.GetDestination: TcxDBVerticalGrid;
begin
Result := TcxDBVerticalGrid(inherited Destination);
end;
{ TcxDXRTTIConverter }
class function TcxDXRTTIConverter.GetSourceClassName: string;
begin
Result := 'TdxRTTIInspector';
end;
procedure TcxDXRTTIConverter.DoRealImport;
begin
inherited DoRealImport;
TcxCustomRTTIInspector(Destination).InspectedObject :=
TPersistent(GetClassProperty(Source, 'InspectedObject'));
end;
procedure TcxDXRTTIConverter.ImportRows;
begin
//do nothing
end;
initialization
ConverterFactory(cxVGGroupConverterName).RegisterConverter('DX Inspector Converter', TcxDXInspConverter);
ConverterFactory(cxDBVGGroupConverterName).RegisterConverter('DX DBInspector Converter', TcxDXDBInspConverter);
ConverterFactory(cxRTTIVGGroupConverterName).RegisterConverter('DX RTTIInspector Converter', TcxDXRTTIConverter);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -