Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 14.02.2023, 21:21   #11
leon2009sp
Форумчанин
 
Регистрация: 22.12.2015
Сообщений: 119
Лампочка еррор

я про
Код:
 strs. sec := 'section'+ sec;
и
Код:
Result.x0 := IniFile.ReadString('key_1', rec.x0, 'faild_0');
значит тоже надо менять result = Result.x0 = Result.sec
leon2009sp вне форума Ответить с цитированием
Старый 14.02.2023, 21:56   #12
leon2009sp
Форумчанин
 
Регистрация: 22.12.2015
Сообщений: 119
Радость нет

Код:
with IniRead(IniFile, strs) do begin
    for x := 1 to 3 do begin
      sec := 'x'+inttostr(x);
      memo5.Lines.Add(sec);
      Edit1.Text:=sec;
      Edit2.Text:=sec;
      Edit3.Text:=sec;
    end;
   end;
   IniFile.Free;
   end;
sec = это string; поэтому и выводит в результат section 1 2 3 а x1,x2,x3 это не string поэтому и выводит результат который нужен.

т.е. через FOR это будет strs+'x1' := 'section1'; а не так: strs.x1 := 'section1';

Последний раз редактировалось leon2009sp; 14.02.2023 в 22:00. Причина: 1
leon2009sp вне форума Ответить с цитированием
Старый 14.02.2023, 22:21   #13
macomics
Участник клуба
 
Регистрация: 17.04.2022
Сообщений: 1,833
По умолчанию

Так объявите массив вместо структуры
Код:
type TiniRec = array of string;

procedure IniRead(IniFile: TIniFile; var rec: TiniRec); stdcall;
var
   i: LongInt;
begin
   for i := Low(rec) to High(rec) do
      rec[i] := IniFile.ReadString('key_1', rec[i], 'faled');
end;
Код:
type TiniRec = array of String;

procedure IniRead(IniFile:TINIFile; var rec: TiniRec); stdcall; external 'list.dll' index 4;

procedure TForm1.IniFileRead;
var
   IniFile: TIniFile;
   strs: TIniRec
   i: LongInt;
begin
   IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName)+'key.ini');
   SetLength(strs, 500);
   for i := Low(strs) to High(strs) do
      strs[i] := 'section' + inttostr(i+1);
   IniRead(IniFile, strs);
   Edit1.Text:=strs[0];
   Edit2.Text:=strs[1];
   Edit3.Text:=strs[2];
...
   IniFile.Free;
end;
macomics вне форума Ответить с цитированием
Старый 14.02.2023, 22:26   #14
evg_m
Старожил
 
Регистрация: 20.04.2008
Сообщений: 5,526
По умолчанию

Код:
for x:=1 to 500 do begin
  s:=format('section%d', [x]);// 'section' +inttostr(x);
  e:=format('edit%d', [x]);
  (findcomponent(e) as Tedit).text:=ini.readstring('key, s, '');
end;
программа — запись алгоритма на языке понятном транслятору
evg_m на форуме Ответить с цитированием
Старый 14.02.2023, 23:11   #15
leon2009sp
Форумчанин
 
Регистрация: 22.12.2015
Сообщений: 119
Смех Спасибо! учится мне, и учится

Спасибо! учится мне, и учится
а то я тут:
Цитата:
IniFile.WriteInteger('form', 'width', line45);//form учится
IniFile.WriteInteger('form', 'Height', line46);
IniFile.WriteInteger('panel', 'width', line47);//panel
IniFile.WriteInteger('panel', 'Height', line48);
IniFile.WriteInteger('panel', 'left', line49);
IniFile.WriteInteger('panel', 'top', line50);
IniFile.WriteInteger('primary', 'width', line51);//primary
IniFile.WriteInteger('primary', 'Height', line52);
IniFile.WriteInteger('primary', 'left', line53);
IniFile.WriteInteger('primary', 'top', line54);
IniFile.WriteInteger('secundary', 'width', line55);//secundary
IniFile.WriteInteger('secundary', 'Height', line56);
IniFile.WriteInteger('secundary', 'left', line57);
IniFile.WriteInteger('secundary', 'top', line58);
IniFile.WriteInteger('tertiary', 'width', line59);//tertiary
IniFile.WriteInteger('tertiary', 'Height', line60);
IniFile.WriteInteger('tertiary', 'left', line61);
IniFile.WriteInteger('tertiary', 'top', line62);
IniFile.WriteInteger('message', 'width', line63);//message
IniFile.WriteInteger('message', 'Height', line64);
IniFile.WriteInteger('message', 'left', line65);
IniFile.WriteInteger('message', 'top', line66);
IniFile.WriteString('key_1', 'section0', line0);//key_1
IniFile.WriteString('key_1', 'section1', line1);
IniFile.WriteString('key_1', 'section2', line2);
IniFile.WriteString('key_1', 'section3', line3);
IniFile.WriteString('key_1', 'section4', line4);
IniFile.WriteString('key_1', 'section5', line5);
IniFile.WriteString('key_1', 'section6', line6);
IniFile.WriteString('key_1', 'section7', line7);
IniFile.WriteString('key_1', 'section8', line8);
IniFile.WriteString('key_1', 'section9', line9);
IniFile.WriteString('key_1', 'section10', line10);
IniFile.WriteString('key_1', 'section11', line11);
IniFile.WriteString('key_1', 'section12', line12);
IniFile.WriteString('key_1', 'section13', line13);
IniFile.WriteString('key_1', 'section14', line14);
IniFile.WriteString('key_2', 'section15', line15);//key_2
IniFile.WriteString('key_2', 'section16', line16);
IniFile.WriteString('key_2', 'section17', line17);
IniFile.WriteString('key_2', 'section18', line18);
IniFile.WriteString('key_2', 'section19', line19);
IniFile.WriteString('key_2', 'section20', line20);
IniFile.WriteString('key_2', 'section21', line21);
IniFile.WriteString('key_2', 'section22', line22);
IniFile.WriteString('key_2', 'section23', line23);
IniFile.WriteString('key_2', 'section24', line24);
IniFile.WriteString('key_2', 'section25', line25);
IniFile.WriteString('key_2', 'section26', line26);
IniFile.WriteString('key_2', 'section27', line27);
IniFile.WriteString('key_2', 'section28', line28);
IniFile.WriteString('key_2', 'section29', line29);
IniFile.WriteString('key_3', 'section30', line30);//key_3
IniFile.WriteString('key_3', 'section31', line31);
IniFile.WriteString('key_3', 'section32', line32);
IniFile.WriteString('key_3', 'section33', line33);
IniFile.WriteString('key_3', 'section34', line34);
IniFile.WriteString('key_3', 'section35', line35);
IniFile.WriteString('key_3', 'section36', line36);
IniFile.WriteString('key_3', 'section37', line37);
IniFile.WriteString('key_3', 'section38', line38);
IniFile.WriteString('key_3', 'section39', line39);
IniFile.WriteString('key_3', 'section40', line40);
IniFile.WriteString('key_3', 'section41', line41);
IniFile.WriteString('key_3', 'section42', line42);
IniFile.WriteString('key_3', 'section43', line43);
IniFile.WriteString('key_3', 'section44', line44);
leon2009sp вне форума Ответить с цитированием
Старый 15.02.2023, 09:26   #16
leon2009sp
Форумчанин
 
Регистрация: 22.12.2015
Сообщений: 119
Восклицание ошибка_3

Здравствуйте! что я делаю не так:?
Код:
type TiniRec = array of string;

function IniWrite(IniFile: TIniFile; keywrite:string; var recwrite: TiniRec; text:string):TiniRec; stdcall;
var
   i: LongInt;
begin
   for i := Low(recwrite) to High(recwrite) do begin
      //rec[i] := IniFile.ReadString(key, rec[i], 'faled');
      IniFile.WriteString(keywrite, recwrite[i], text);
   end;
Код:
type TiniRec = array of String;

function IniWrite(IniFile2: TIniFile; keywrite:string; var recwrite: TiniRec; text:string):TiniRec; stdcall; external 'list.dll' index 3;

procedure TForm1.IniFileWrite;    //INI_WERITE
var
    IniFile2: TIniFile;
    stwrite: TIniRec; i:integer;
begin
  IniFile2 := TIniFile.Create(ExtractFilePath(Application.ExeName)+'key.ini');
  SetLength(stwrite, 15);
  for i := Low(stwrite) to High(stwrite) do  stwrite[i] := 'section' + inttostr(i);
  IniWrite(IniFile2, 'key_1', stwrite, memo3.Lines[i]);
  IniWrite(IniFile2, 'key_2', stwrite, memo4.Lines[i]);
  IniFile2.Free;

Последний раз редактировалось leon2009sp; 15.02.2023 в 09:29.
leon2009sp вне форума Ответить с цитированием
Старый 15.02.2023, 09:49   #17
leon2009sp
Форумчанин
 
Регистрация: 22.12.2015
Сообщений: 119
Смех ответ

я сделал так:
Код:
function IniWrite(IniFile2: TIniFile; keywrite,section,text:string):string; stdcall; external 'list.dll' index 3;

procedure TForm1.IniFileWrite;    //INI_WERITE
var
    IniFile2: TIniFile;  i,lines:integer;  i2 :  String;
begin
  IniFile2 := TIniFile.Create(ExtractFilePath(Application.ExeName)+'key.ini');
  SetLength(i2, 15);
 // for i := Low(stwrite) to High(stwrite) do  stwrite[i] := 'section' + inttostr(i);

  for i := 0 to 10 do begin i2 := 'section' + inttostr(i);
  IniWrite(IniFile2, 'key_1', i2, memo3.Lines[i]);
                            end;
 // IniWrite(IniFile2, 'key_2', stwrite, memo4.Lines[i]);
  IniFile2.Free;
работает = но не уверен, что это правильный код.

Модернизация:

Код:
procedure TForm1.IniFileWrite;    //INI_WERITE
var
    IniFile: TIniFile;  i:integer;  lmem3:  String;
begin
  IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName)+'key.ini');
  SetLength(lmem3, memo3.Lines.Count);
  for i := 0 to memo3.Lines.Count-1 do begin lmem3 := 'section' + inttostr(i);
  IniWrite(IniFile, 'key_1', lmem3, memo3.Lines[i]);
  IniWrite(IniFile, 'key_2', lmem3, memo4.Lines[i]);
  IniWrite(IniFile, 'key_3', lmem3, memo5.Lines[i]);
  end;
  IniFile.Free;

Последний раз редактировалось leon2009sp; 15.02.2023 в 09:57. Причина: я лошара
leon2009sp вне форума Ответить с цитированием
Старый 15.02.2023, 12:22   #18
leon2009sp
Форумчанин
 
Регистрация: 22.12.2015
Сообщений: 119
Стрелка а так я загружаю

загружаю кей_1 в мемо3, кей_2 в мемо4 и кей_3 в мемо5
Код:
rocedure TForm1.IniFileRead;    //INIREAD
var
strs: TIniRec; i: LongInt;
begin
  IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName)+'key.ini');
  try
  SetLength(strs, 15);
  for i := Low(strs) to High(strs) do strs[i] := 'section' + inttostr(i);
  IniRead(IniFile, 'key_1', strs);  for I := 0 to 15-1 do memo3.Lines.Add(strs[i]);
  for i := Low(strs) to High(strs) do strs[i] := 'section' + inttostr(i);
  IniRead(IniFile, 'key_2', strs);  for I := 0 to 15-1 do memo4.Lines.Add(strs[i]);
  for i := Low(strs) to High(strs) do strs[i] := 'section' + inttostr(i);
  IniRead(IniFile, 'key_3', strs);  for I := 0 to 15-1 do memo5.Lines.Add(strs[i]);
  finally
  IniFile.Free;
  end;
end;
leon2009sp вне форума Ответить с цитированием
Старый 15.02.2023, 12:58   #19
leon2009sp
Форумчанин
 
Регистрация: 22.12.2015
Сообщений: 119
Счастье а это математика

а здесь сначала считаем сколько секций в ini и только потом выводим
Код:
rocedure TForm1.IniFileRead;    //INIREAD
var
strs: TIniRec; i: LongInt; sl1,sl2,sl3:TStringList;
begin
  IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName)+'key.ini');
  sl1:= TStringList.Create;
  sl2:= TStringList.Create;
  sl3:= TStringList.Create;
  IniFile.ReadSectionValues('key_1',sl1);
  IniFile.ReadSectionValues('key_2',sl2);
  IniFile.ReadSectionValues('key_3',sl3);
  try
  SetLength(strs, 15);
  for i := Low(strs) to High(strs) do strs[i] := 'section' + inttostr(i);
  IniRead(IniFile, 'key_1', strs);  for I := 0 to sl1.Count-1 do memo3.Lines.Add(strs[i]);
  for i := Low(strs) to High(strs) do strs[i] := 'section' + inttostr(i);
  IniRead(IniFile, 'key_2', strs);  for I := 0 to sl2.Count-1 do memo4.Lines.Add(strs[i]);
  for i := Low(strs) to High(strs) do strs[i] := 'section' + inttostr(i);
  IniRead(IniFile, 'key_3', strs);  for I := 0 to sl3.Count-1 do memo5.Lines.Add(strs[i]);
  finally
  IniFile.Free;
  end;
end;
я сделал так: т.к. не знаю как сократить
Код:
  IniFile.ReadSectionValues('key_1',sl1);
  IniFile.ReadSectionValues('key_2',sl2);
  IniFile.ReadSectionValues('key_3',sl3);
leon2009sp вне форума Ответить с цитированием
Старый 15.02.2023, 15:30   #20
leon2009sp
Форумчанин
 
Регистрация: 22.12.2015
Сообщений: 119
Сообщение Можно уменьшить код

Можно как ни будь еще уменьшить код? или это предел?
Код:
procedure TForm1.IniFileRead;    //INIREAD
var
strs: TIniRec; i: LongInt; sl1,sl2,sl3:TStringList;
begin
  IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName)+'key.ini');
  sl1:= TStringList.Create;
  sl2:= TStringList.Create;
  sl3:= TStringList.Create;
  IniFile.ReadSectionValues('key_1',sl1);
  IniFile.ReadSectionValues('key_2',sl2);
  IniFile.ReadSectionValues('key_3',sl3);
  try
  Form1.Width:= IniFile.ReadInteger('form', 'width', form1.Width); Form1.Height:=IniFile.ReadInteger('form', 'height', form1.Height);
  //panel1
  Panel1.Width:= IniFile.ReadInteger('Panel', 'width', Panel1.Width); Panel1.Height:=IniFile.ReadInteger('Panel', 'height', Panel1.Height);
  Panel1.Left:=  IniFile.ReadInteger('Panel', 'left', Panel1.Left);   Panel1.Top:=   IniFile.ReadInteger('Panel', 'top', Panel1.Top);
  //primary
  Panel3.Width:= IniFile.ReadInteger('primary', 'width', Panel3.Width); Panel3.Height:=IniFile.ReadInteger('primary', 'height', Panel3.Height);
  Panel3.Left:=  IniFile.ReadInteger('primary', 'left', Panel3.Left);   Panel3.Top:=   IniFile.ReadInteger('primary', 'top', Panel3.Top);
  //secundary
  Panel4.Width:= IniFile.ReadInteger('secundary', 'width', Panel4.Width); Panel4.Height:=IniFile.ReadInteger('secundary', 'height', Panel4.Height);
  Panel4.Left:=  IniFile.ReadInteger('secundary', 'left', Panel4.Left);   Panel4.Top:=   IniFile.ReadInteger('secundary', 'top', Panel4.Top);
  //tertiary
  Panel5.Width:= IniFile.ReadInteger('tertiary', 'width', Panel5.Width);  Panel5.Height:=IniFile.ReadInteger('tertiary', 'height', Panel5.Height);
  Panel5.Left:=  IniFile.ReadInteger('tertiary', 'left', Panel5.Left);    Panel5.Top:=   IniFile.ReadInteger('tertiary', 'top', Panel5.Top);
  //message
  Panel6.Width:= IniFile.ReadInteger('message', 'width', Panel6.Width);   Panel6.Height:=IniFile.ReadInteger('message', 'height', Panel6.Height);
  Panel6.Left:=  IniFile.ReadInteger('message', 'left', Panel6.Left);     Panel6.Top:=   IniFile.ReadInteger('message', 'top', Panel6.Top);
  //section
  SetLength(strs, 15);
  for i := Low(strs) to High(strs) do strs[i] := 'section' + inttostr(i);
  IniRead(IniFile, 'key_1', strs);  for I := 0 to sl1.Count-1 do memo3.Lines.Add(strs[i]);
  for i := Low(strs) to High(strs) do strs[i] := 'section' + inttostr(i);
  IniRead(IniFile, 'key_2', strs);  for I := 0 to sl2.Count-1 do memo4.Lines.Add(strs[i]);
  for i := Low(strs) to High(strs) do strs[i] := 'section' + inttostr(i);
  IniRead(IniFile, 'key_3', strs);  for I := 0 to sl3.Count-1 do memo5.Lines.Add(strs[i]);
  finally
  IniFile.Free;
  end;
end;
leon2009sp вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц