procedure TFormSettings.ComboBoxTransersChange(Sender: TObject);
//var str1, str2 : string;
begin
ComboBoxOracleHome.ItemIndex:=ComboBoxOracleHome.Items.IndexOf(transfer_local[TComboBox(Sender).itemIndex].cp_o_homeName);
//TComboBox(Sender).itemIndex:=1;
if (ComboBoxOracleHome.ItemIndex<=0)
and (ComboBoxOracleHome.Items.Count>=2)
then UpdateOracleHome(ComboBoxOracleHome.Items[1]);
ComboBoxDBConnect.ItemIndex := ComboBoxDBConnect.Items.IndexOf(copy(transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString, pos('@',transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString)+1, length(transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString)-pos('@',transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString)));
LabeledEditOracleUser.Text :=
//str2 :=
copy(
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString,
1,
pos(
'/',
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString
) -1
);
LabeledEditOraclePassword.Text :=
//str1 :=
copy(
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString,
pos(
'/',
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString
)+1,
pos(
'@',
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString
)
-pos(
'/',
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString
) -1
);
end;
порча памяти при выделении подстроки
Есть код
Код:
transfer и transfer_index - глобальные переменные приложения
значения в transfer_local заносятся следующим кодом
Код:
procedure TFormSettings.FormShow(Sender: TObject);
var Registry : TRegistry;
RegistryKeys : TStrings;
RegistryKeysIndex,
TransferIndex2 : integer;
begin
ComboBoxOracleHome.Clear;
ComboBoxOracleHome.AddItem('',nil);
Registry := TRegistry.Create(KEY_READ);
try
Registry.RootKey := HKEY_LOCAL_MACHINE;
// False because we do not want to create it if it doesn't exist
if Registry.KeyExists('\SOFTWARE\ORACLE')
then
begin
Registry.OpenKeyReadOnly('\SOFTWARE\ORACLE');
RegistryKeys:=TStringList.Create;
try
Registry.GetKeyNames(RegistryKeys);
for RegistryKeysIndex := 0 to RegistryKeys.Count - 1 do
begin
Registry.OpenKeyReadOnly('\SOFTWARE\ORACLE\'+RegistryKeys[RegistryKeysIndex]);
if Registry.ValueExists('ORACLE_HOME_NAME')
then ComboBoxOracleHome.AddItem(Registry.ReadString('ORACLE_HOME_NAME'),nil);
end;
finally
RegistryKeys.Free;
end;
end;
finally
Registry.Free;
end;
ComboBoxTransers.Clear;
for TransferIndex2 := 0 to length(transfer) - 1 do
ComboBoxTransers.AddItem(transfer[TransferIndex2].name, nil);
transfer_local:=transfer;
ComboBoxTransers.ItemIndex:=transfer_index;
ComboBoxTransers.OnChange(ComboBoxTransers);
end;
var Registry : TRegistry;
RegistryKeys : TStrings;
RegistryKeysIndex,
TransferIndex2 : integer;
begin
ComboBoxOracleHome.Clear;
ComboBoxOracleHome.AddItem('',nil);
Registry := TRegistry.Create(KEY_READ);
try
Registry.RootKey := HKEY_LOCAL_MACHINE;
// False because we do not want to create it if it doesn't exist
if Registry.KeyExists('\SOFTWARE\ORACLE')
then
begin
Registry.OpenKeyReadOnly('\SOFTWARE\ORACLE');
RegistryKeys:=TStringList.Create;
try
Registry.GetKeyNames(RegistryKeys);
for RegistryKeysIndex := 0 to RegistryKeys.Count - 1 do
begin
Registry.OpenKeyReadOnly('\SOFTWARE\ORACLE\'+RegistryKeys[RegistryKeysIndex]);
if Registry.ValueExists('ORACLE_HOME_NAME')
then ComboBoxOracleHome.AddItem(Registry.ReadString('ORACLE_HOME_NAME'),nil);
end;
finally
RegistryKeys.Free;
end;
end;
finally
Registry.Free;
end;
ComboBoxTransers.Clear;
for TransferIndex2 := 0 to length(transfer) - 1 do
ComboBoxTransers.AddItem(transfer[TransferIndex2].name, nil);
transfer_local:=transfer;
ComboBoxTransers.ItemIndex:=transfer_index;
ComboBoxTransers.OnChange(ComboBoxTransers);
end;
Код:
unit UnitConstant;
interface
type
t_macros_item = record
name,
select,
insert,
select_recordCount : string;
end;
t_macros = array of t_macros_item;
t_transfer_item = record
name : string;
cp_a_connectionString : string; // строка соединения ADO
cp_o_homeName : string; // название клиента ORACLE
cp_o_connectionString : string; // строка соединения вида user/password@database
macros : t_macros;
before_macros_o,
afte_macros_o : string;
end;
t_transfer = array of t_transfer_item;
var
transfer : t_transfer;
transfer_index : integer;
interface
type
t_macros_item = record
name,
select,
insert,
select_recordCount : string;
end;
t_macros = array of t_macros_item;
t_transfer_item = record
name : string;
cp_a_connectionString : string; // строка соединения ADO
cp_o_homeName : string; // название клиента ORACLE
cp_o_connectionString : string; // строка соединения вида user/password@database
macros : t_macros;
before_macros_o,
afte_macros_o : string;
end;
t_transfer = array of t_transfer_item;
var
transfer : t_transfer;
transfer_index : integer;
Теперь собственно в чём сложность.
при выполнении кода из первой цитаты
Код:
// строка 1
LabeledEditOracleUser.Text :=
//str2 :=
copy(
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString,
1,
pos(
'/',
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString
) -1
);
LabeledEditOraclePassword.Text :=
//str1 :=
copy(
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString,
pos(
'/',
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString
)+1,
pos(
'@',
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString
)
-pos(
'/',
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString
) -1
);
LabeledEditOracleUser.Text :=
//str2 :=
copy(
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString,
1,
pos(
'/',
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString
) -1
);
LabeledEditOraclePassword.Text :=
//str1 :=
copy(
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString,
pos(
'/',
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString
)+1,
pos(
'@',
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString
)
-pos(
'/',
transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString
) -1
);
Если же реализовать вариант
Код:
// строка 1
LabeledEditOraclePassword.Text :=
//str1 :=
...; LabeledEditOracleUser.Text :=
//str2 :=
...;
LabeledEditOraclePassword.Text :=
//str1 :=
...; LabeledEditOracleUser.Text :=
//str2 :=
...;
Более того ! затирается оно не только в transfer_local, но и в transfer (!), которая в данном методе даже не используется....
Кроме того, такое происходит только при открытии формы, т.е.
Код:
procedure TFormSettings.FormShow(Sender: TObject);
........
begin
.......
transfer_local:=transfer;
ComboBoxTransers.ItemIndex:=transfer_index;
ComboBoxTransers.OnChange(ComboBoxTransers);
end;
........
begin
.......
transfer_local:=transfer;
ComboBoxTransers.ItemIndex:=transfer_index;
ComboBoxTransers.OnChange(ComboBoxTransers);
end;
Не менее интерестно так же то, что если заменить LabeledEditOraclePassword.Text на str1 и LabeledEditOracleUser.Text на str2, то затирания данных так же не случается.
Код:
//LabeledEditOraclePassword.Text :=
str1 :=...;
//LabeledEditOracleUser.Text :=
str2 :=...;
str1 :=...;
//LabeledEditOracleUser.Text :=
str2 :=...;
Заранее спасибо :)
Код:
procedure TFormSettings.ComboBoxTransersChange(Sender: TObject);
var str1, str2 : string;
begin
ComboBoxOracleHome.ItemIndex:=ComboBoxOracleHome.Items.IndexOf(transfer_local[TComboBox(Sender).itemIndex].cp_o_homeName);
//TComboBox(Sender).itemIndex:=1;
if (ComboBoxOracleHome.ItemIndex<=0)
and (ComboBoxOracleHome.Items.Count>=2)
then UpdateOracleHome(ComboBoxOracleHome.Items[1]);
ComboBoxDBConnect.ItemIndex := ComboBoxDBConnect.Items.IndexOf(copy(transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString, pos('@',transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString)+1, length(transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString)-pos('@',transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString)));
str2 := ...;
LabeledEditOracleUser.Text := str2;
str1 := ...;
LabeledEditOraclePassword.Text := str1;
end;
var str1, str2 : string;
begin
ComboBoxOracleHome.ItemIndex:=ComboBoxOracleHome.Items.IndexOf(transfer_local[TComboBox(Sender).itemIndex].cp_o_homeName);
//TComboBox(Sender).itemIndex:=1;
if (ComboBoxOracleHome.ItemIndex<=0)
and (ComboBoxOracleHome.Items.Count>=2)
then UpdateOracleHome(ComboBoxOracleHome.Items[1]);
ComboBoxDBConnect.ItemIndex := ComboBoxDBConnect.Items.IndexOf(copy(transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString, pos('@',transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString)+1, length(transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString)-pos('@',transfer_local[TComboBox(Sender).itemIndex].cp_o_connectionString)));
str2 := ...;
LabeledEditOracleUser.Text := str2;
str1 := ...;
LabeledEditOraclePassword.Text := str1;
end;
Решение пока не найдено.
p.s. Используется BDS 2006.