Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > save line to txt file


Автор: muratboy31 11.2.2010, 12:26
why it doesnt save the combobox text to rapor.dat file ?

Код

procedure TForm1.spdBtnClick(Sender: TObject);
var
  fileData : TStringList;
  lines, x : Integer;
  saveLine : String;
begin
  saveLine:=sComboBox1.Text;
   fileData := TStringList.Create;
   fileData.LoadFromFile('Rapor.dat');
   lines := fileData.Count;
      for x := lines-1 downto (lines div 2) do
      begin
        saveLine := fileData[lines-x-1];
        fileData[lines-x-1] := fileData[x];
        fileData[x] := saveLine;
      end;
      for x := 0 to lines-1 do
        ShowMessage(fileData[x]);
        fileData.SaveToFile('Rapor.dat');
end;

Автор: Mikel 11.2.2010, 13:44
But it shouldn't save the text from combobox. May be you need this?
Код

procedure TForm1.spdBtnClick(Sender: TObject);
var
  fileData : TStringList;
  lines, x : Integer;
  saveLine : String;
begin
   fileData := TStringList.Create;
   fileData.text:=sComboBox1.Text;
   lines := fileData.Count;
      for x := lines-1 downto (lines div 2) do
      begin
        saveLine := fileData[lines-x-1];
        fileData[lines-x-1] := fileData[x];
        fileData[x] := saveLine;
      end;
      for x := 0 to lines-1 do
        ShowMessage(fileData[x]);
        fileData.SaveToFile('Rapor.dat');
end;

Автор: muratboy31 11.2.2010, 14:01
thanks for helping Mikel but it deletes all the lines in the rapor.dat... i want to add line to rapor.dat from combobox...

i just want it to save combobox.text and save it to rapor.dat... not all combobox items...

before....
in rapor.dat file :
Цитата

Jack
Clair
Michele


after...
combobox.text   :  Blair
in rapor.dat file :
Цитата

Blair
Jack
Clair
Michele


Автор: Mikel 11.2.2010, 14:21
And why do you invert them? Try this:

Код

procedure TForm1.spdBtnClick(Sender: TObject);
var
  fileData : TStringList;
  lines, x : Integer;
  saveLine : String;
begin
  saveLine:=sComboBox1.Text;
   fileData := TStringList.Create;
   fileData.LoadFromFile('Rapor.dat');
   fileData.Insert(0,saveLine);
   fileData.SaveToFile('Rapor.dat');

   fileData.Free;
end;

Автор: muratboy31 11.2.2010, 14:24
Mikel THANKS ALOOOOOOTTTTTTTTT smile 
perfect help...   smile  


just another question;
is it possible not to save the same text to rapor.dat ?

if there is a text Blair in rapor.dat then dont save it to rapor.dat...

Автор: Mikel 11.2.2010, 14:36
You may check the index of line to insert in text file before inserting:

Код

procedure TForm1.spdBtnClick(Sender: TObject);
var
  fileData : TStringList;
  lines, x : Integer;
  saveLine : String;
begin
  saveLine:=sComboBox1.Text;
   fileData := TStringList.Create;
   fileData.LoadFromFile('Rapor.dat');
   if fileData.IndexOf(saveLine)=-1
      then begin
         fileData.Insert(0,saveLine);
         fileData.SaveToFile('Rapor.dat');
      end;
   fileData.Free;
end;

Автор: muratboy31 11.2.2010, 14:44
i understand it, thanks alot... 
  smile 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)