TCustomDBGridEh.RestoreColumnsLayoutIni(IniFileName: String;Section: String; Res

  • 主题发起人 主题发起人 小溪水
  • 开始时间 开始时间

小溪水

Unregistered / Unconfirmed
GUEST, unregistred user!
TCustomDBGridEh.RestoreColumnsLayoutIni(IniFileName: String;Section: String;
RestoreParams: TColumnEhRestoreParams);这里RestoreParams该怎么写入? ( 积分: 20 )
<br />[red]想让dbgrideh表格的格式从前面用[/red]
[blue]DBGridEh1.SaveGridLayoutIni('D:/delphi_测试/报表测试/dayintz.ini','grgzhz',True);[/blue]
[red]保存的格式恢复回来,DBGridEh1 控件里有这样的过程:[/red]
[blue]procedure TCustomDBGridEh.RestoreColumnsLayoutIni(IniFileName: String;
Section: String;
RestoreParams: TColumnEhRestoreParams);
可是我该怎么写这个RestoreColumnsLayoutIni?
RestoreColumnsLayoutIni('D:/delphi_测试/报表测试/dayintz.ini','grgzhz',??);
后面的RestoreParams: TColumnEhRestoreParams 怎么写呢?试了好几个都不对 [/blue]
[black]-----------------------------------
部分控件源码:
TColumnEhRestoreParam = (crpColIndexEh, crpColWidthsEh, crpSortMarkerEh, crpColVisibleEh,
crpDropDownRowsEh, crpDropDownWidthEh);
TColumnEhRestoreParams = set of TColumnEhRestoreParam;
----------------------------------------------------------------
procedure TCustomDBGridEh.RestoreColumnsLayoutProducer(ARegIni: TObject;
Section: String;
RestoreParams: TColumnEhRestoreParams);
type
TColumnInfo = record
Column: TColumnEh;
EndIndex: Integer;
SortMarker: TSortMarkerEh;
SortIndex: Integer;
end;
PColumnArray = ^TColumnArray;
TColumnArray = array[0..0] of TColumnInfo;
const
Delims = [' ', ','];
var
I, J: Integer;
S: string;
ColumnArray: PColumnArray;
AAutoFitColWidth: Boolean;
begin
AAutoFitColWidth := False;
begin
Update;
try
if (AutoFitColWidths) then
begin
AutoFitColWidths := False;
AAutoFitColWidth := True;
end;
with Columnsdo
begin
ColumnArray := AllocMem(Count * SizeOf(TColumnInfo));
try
for I := 0 to Count - 1do
begin
if (ARegIni is TRegIniFile)
then
S := TRegIniFile(ARegIni).ReadString(Section, Format('%s.%s', [Name, Items.FieldName]), '')
else
S := TCustomIniFile(ARegIni).ReadString(Section, Format('%s.%s', [Name, Items.FieldName]), '');
ColumnArray^.Column := Items;
ColumnArray^.EndIndex := Items.Index;
if S <> '' then
begin
ColumnArray^.EndIndex := StrToIntDef(ExtractWord(1, S, Delims),
ColumnArray^.EndIndex);
if (crpColWidthsEh in RestoreParams) then
Items.Width := StrToIntDef(ExtractWord(2, S, Delims),
Items.Width);
if (crpSortMarkerEh in RestoreParams) then
Items.Title.SortMarker := TSortMarkerEh(StrToIntDef(ExtractWord(3, S, Delims),
Integer(Items.Title.SortMarker)));
if (crpColVisibleEh in RestoreParams) then
Items.Visible := Boolean(StrToIntDef(ExtractWord(4, S, Delims), Integer(Items.Visible)));
if (crpSortMarkerEh in RestoreParams) then
ColumnArray^.SortIndex := StrToIntDef(ExtractWord(5, S, Delims), 0);
if (crpDropDownRowsEh in RestoreParams) then
Items.DropDownRows := StrToIntDef(ExtractWord(6, S, Delims), Items.DropDownRows);
if (crpDropDownWidthEh in RestoreParams) then
Items.DropDownWidth := StrToIntDef(ExtractWord(7, S, Delims), Items.DropDownWidth);
end;
end;
if (crpSortMarkerEh in RestoreParams) then
for I := 0 to Count - 1do
Items.Title.SortIndex := ColumnArray^.SortIndex;
if (crpColIndexEh in RestoreParams) then
for I := 0 to Count - 1do
for J := 0 to Count - 1do
if ColumnArray^[J].EndIndex = I then
begin
ColumnArray^[J].Column.Index := ColumnArray^[J].EndIndex;
Break;
end;

finally
FreeMem(Pointer(ColumnArray));
end;
end;
finally
EndUpdate;
if (AAutoFitColWidth = True)
then
AutoFitColWidths := True
else
LayoutChanged;
end;
end;
------------------------------------------------------------------
[/black]
 
[red]想让dbgrideh表格的格式从前面用[/red]
[blue]DBGridEh1.SaveGridLayoutIni('D:/delphi_测试/报表测试/dayintz.ini','grgzhz',True);[/blue]
[red]保存的格式恢复回来,DBGridEh1 控件里有这样的过程:[/red]
[blue]procedure TCustomDBGridEh.RestoreColumnsLayoutIni(IniFileName: String;
Section: String;
RestoreParams: TColumnEhRestoreParams);
可是我该怎么写这个RestoreColumnsLayoutIni?
RestoreColumnsLayoutIni('D:/delphi_测试/报表测试/dayintz.ini','grgzhz',??);
后面的RestoreParams: TColumnEhRestoreParams 怎么写呢?试了好几个都不对 [/blue]
[black]-----------------------------------
部分控件源码:
TColumnEhRestoreParam = (crpColIndexEh, crpColWidthsEh, crpSortMarkerEh, crpColVisibleEh,
crpDropDownRowsEh, crpDropDownWidthEh);
TColumnEhRestoreParams = set of TColumnEhRestoreParam;
----------------------------------------------------------------
procedure TCustomDBGridEh.RestoreColumnsLayoutProducer(ARegIni: TObject;
Section: String;
RestoreParams: TColumnEhRestoreParams);
type
TColumnInfo = record
Column: TColumnEh;
EndIndex: Integer;
SortMarker: TSortMarkerEh;
SortIndex: Integer;
end;
PColumnArray = ^TColumnArray;
TColumnArray = array[0..0] of TColumnInfo;
const
Delims = [' ', ','];
var
I, J: Integer;
S: string;
ColumnArray: PColumnArray;
AAutoFitColWidth: Boolean;
begin
AAutoFitColWidth := False;
begin
Update;
try
if (AutoFitColWidths) then
begin
AutoFitColWidths := False;
AAutoFitColWidth := True;
end;
with Columnsdo
begin
ColumnArray := AllocMem(Count * SizeOf(TColumnInfo));
try
for I := 0 to Count - 1do
begin
if (ARegIni is TRegIniFile)
then
S := TRegIniFile(ARegIni).ReadString(Section, Format('%s.%s', [Name, Items.FieldName]), '')
else
S := TCustomIniFile(ARegIni).ReadString(Section, Format('%s.%s', [Name, Items.FieldName]), '');
ColumnArray^.Column := Items;
ColumnArray^.EndIndex := Items.Index;
if S <> '' then
begin
ColumnArray^.EndIndex := StrToIntDef(ExtractWord(1, S, Delims),
ColumnArray^.EndIndex);
if (crpColWidthsEh in RestoreParams) then
Items.Width := StrToIntDef(ExtractWord(2, S, Delims),
Items.Width);
if (crpSortMarkerEh in RestoreParams) then
Items.Title.SortMarker := TSortMarkerEh(StrToIntDef(ExtractWord(3, S, Delims),
Integer(Items.Title.SortMarker)));
if (crpColVisibleEh in RestoreParams) then
Items.Visible := Boolean(StrToIntDef(ExtractWord(4, S, Delims), Integer(Items.Visible)));
if (crpSortMarkerEh in RestoreParams) then
ColumnArray^.SortIndex := StrToIntDef(ExtractWord(5, S, Delims), 0);
if (crpDropDownRowsEh in RestoreParams) then
Items.DropDownRows := StrToIntDef(ExtractWord(6, S, Delims), Items.DropDownRows);
if (crpDropDownWidthEh in RestoreParams) then
Items.DropDownWidth := StrToIntDef(ExtractWord(7, S, Delims), Items.DropDownWidth);
end;
end;
if (crpSortMarkerEh in RestoreParams) then
for I := 0 to Count - 1do
Items.Title.SortIndex := ColumnArray^.SortIndex;
if (crpColIndexEh in RestoreParams) then
for I := 0 to Count - 1do
for J := 0 to Count - 1do
if ColumnArray^[J].EndIndex = I then
begin
ColumnArray^[J].Column.Index := ColumnArray^[J].EndIndex;
Break;
end;

finally
FreeMem(Pointer(ColumnArray));
end;
end;
finally
EndUpdate;
if (AAutoFitColWidth = True)
then
AutoFitColWidths := True
else
LayoutChanged;
end;
end;
------------------------------------------------------------------
[/black]
 
以下是我写的从Ini文件恢复一个Form上所有DBGridEh的过程
procedure LoadGridLayout(AForm: TForm);
var
I: integer;
GridName, FormName, MyFile: string;
Section: string;
begin

MyFile := ExtractFilePath(ParamStr(0))+'Layout.ini';
for I := 0 to AForm.ComponentCount - 1do
begin
if AForm.Components is TDBGridEh then
begin
Section := AForm.Name + '.' + TDBGridEh(AForm.Components).Name;
TDBGridEh(AForm.Components).RestoreColumnsLayoutIni(MyFile, Section, [crpColIndexEh, crpColWidthsEh]);
end;
end;
end;
 
谢谢 protossgffnxk 的提醒,问题解决了:
dbgrideh1.RestoreGridLayoutIni('D:/梁的例子/报表测试/baobiao_zdy.ini','grhz',[grpColIndexEh, grpColWidthsEh, grpSortMarkerEh, grpColVisibleEh,
grpRowHeightEh, grpDropDownRowsEh, grpDropDownWidthEh]);
原来这样写! 请收分:
 
多人接受答案了。
 

Similar threads

后退
顶部