娃
娃娃
Unregistered / Unconfirmed
GUEST, unregistred user!
同样的代码
=============================================这样写就是正确的
myIni := TIniFile.Create(IniFileName);
lst_ColWidthList := TStringList.Create
<============就这一句。
with myIni do
try
for li_Count := 0 to Self.ComponentCount -1 do
begin
//处理TDBGridEh
if Self.Components[li_Count] is TDBGridEh then
begin
dbgTemp := Self.Components[li_Count] as TDBGridEh;
ls_WidthInfo := Trim(ReadString(Self.Name, dbgTemp.Name, ''));
if ls_WidthInfo <> '' then
begin
lst_ColWidthList.Clear;
lst_ColWidthList.Delimiter := ',';
lst_ColWidthList.DelimitedText := ls_WidthInfo;
for li_Col := 0 to dbgTemp.Columns.Count - 1 do
if lst_ColWidthList.Count - 1 > li_Col then
begin
li_Width := StrToInt(lst_ColWidthList.Strings[li_Col]);
if li_Width > 0 then dbgTemp.Columns.Items[li_Col].Width := li_Width;
end;
end;
end;
//处理TDBLookupComboBoxEh
if Self.Components[li_Count] is TDBLookupComboBoxEh then
begin
clbTemp := Self.Components[li_Count] as TDBLookupComboBoxEh;
clbTemp.DropDownBox.Sizable := True;
clbTemp.DropDownBox.Width := ReadInteger(Self.Name, (Self.Components[li_Count] as TDBLookupComboBoxEh).Name, 20);
end;
end
//end for
finally
myIni.Free;
lst_ColWidthList.Free;
end;
=============================================这样写就是错误的
这样写会导致继续于这个单元的一个单元中的的所有控件变成nil(跟踪时查到的)
myIni := TIniFile.Create(IniFileName);
with myIni do
try
for li_Count := 0 to Self.ComponentCount -1 do
begin
//处理TDBGridEh
if Self.Components[li_Count] is TDBGridEh then
begin
lst_ColWidthList := TStringList.Create
<============只是换了一下位置
dbgTemp := Self.Components[li_Count] as TDBGridEh;
ls_WidthInfo := Trim(ReadString(Self.Name, dbgTemp.Name, ''));
if ls_WidthInfo <> '' then
begin
lst_ColWidthList.Clear;
lst_ColWidthList.Delimiter := ',';
lst_ColWidthList.DelimitedText := ls_WidthInfo;
for li_Col := 0 to dbgTemp.Columns.Count - 1 do
if lst_ColWidthList.Count - 1 > li_Col then
begin
li_Width := StrToInt(lst_ColWidthList.Strings[li_Col]);
if li_Width > 0 then dbgTemp.Columns.Items[li_Col].Width := li_Width;
end;
end;
end;
//处理TDBLookupComboBoxEh
if Self.Components[li_Count] is TDBLookupComboBoxEh then
begin
clbTemp := Self.Components[li_Count] as TDBLookupComboBoxEh;
clbTemp.DropDownBox.Sizable := True;
clbTemp.DropDownBox.Width := ReadInteger(Self.Name, (Self.Components[li_Count] as TDBLookupComboBoxEh).Name, 20);
end;
end
//end for
finally
myIni.Free;
lst_ColWidthList.Free;
end;
=============================================这样写就是正确的
myIni := TIniFile.Create(IniFileName);
lst_ColWidthList := TStringList.Create
<============就这一句。
with myIni do
try
for li_Count := 0 to Self.ComponentCount -1 do
begin
//处理TDBGridEh
if Self.Components[li_Count] is TDBGridEh then
begin
dbgTemp := Self.Components[li_Count] as TDBGridEh;
ls_WidthInfo := Trim(ReadString(Self.Name, dbgTemp.Name, ''));
if ls_WidthInfo <> '' then
begin
lst_ColWidthList.Clear;
lst_ColWidthList.Delimiter := ',';
lst_ColWidthList.DelimitedText := ls_WidthInfo;
for li_Col := 0 to dbgTemp.Columns.Count - 1 do
if lst_ColWidthList.Count - 1 > li_Col then
begin
li_Width := StrToInt(lst_ColWidthList.Strings[li_Col]);
if li_Width > 0 then dbgTemp.Columns.Items[li_Col].Width := li_Width;
end;
end;
end;
//处理TDBLookupComboBoxEh
if Self.Components[li_Count] is TDBLookupComboBoxEh then
begin
clbTemp := Self.Components[li_Count] as TDBLookupComboBoxEh;
clbTemp.DropDownBox.Sizable := True;
clbTemp.DropDownBox.Width := ReadInteger(Self.Name, (Self.Components[li_Count] as TDBLookupComboBoxEh).Name, 20);
end;
end
//end for
finally
myIni.Free;
lst_ColWidthList.Free;
end;
=============================================这样写就是错误的
这样写会导致继续于这个单元的一个单元中的的所有控件变成nil(跟踪时查到的)
myIni := TIniFile.Create(IniFileName);
with myIni do
try
for li_Count := 0 to Self.ComponentCount -1 do
begin
//处理TDBGridEh
if Self.Components[li_Count] is TDBGridEh then
begin
lst_ColWidthList := TStringList.Create
<============只是换了一下位置
dbgTemp := Self.Components[li_Count] as TDBGridEh;
ls_WidthInfo := Trim(ReadString(Self.Name, dbgTemp.Name, ''));
if ls_WidthInfo <> '' then
begin
lst_ColWidthList.Clear;
lst_ColWidthList.Delimiter := ',';
lst_ColWidthList.DelimitedText := ls_WidthInfo;
for li_Col := 0 to dbgTemp.Columns.Count - 1 do
if lst_ColWidthList.Count - 1 > li_Col then
begin
li_Width := StrToInt(lst_ColWidthList.Strings[li_Col]);
if li_Width > 0 then dbgTemp.Columns.Items[li_Col].Width := li_Width;
end;
end;
end;
//处理TDBLookupComboBoxEh
if Self.Components[li_Count] is TDBLookupComboBoxEh then
begin
clbTemp := Self.Components[li_Count] as TDBLookupComboBoxEh;
clbTemp.DropDownBox.Sizable := True;
clbTemp.DropDownBox.Width := ReadInteger(Self.Name, (Self.Components[li_Count] as TDBLookupComboBoxEh).Name, 20);
end;
end
//end for
finally
myIni.Free;
lst_ColWidthList.Free;
end;