Forum > Beginners
Write to TextFile on specific location
User137:
--- Quote from: howardpc on September 19, 2014, 08:50:42 pm ---You can force textfiles to be seekable with the following routine. I don't recommend it (because it hacks the normally unseen TTextRec file metadata), but it seems to work, at least on Windows. I have not tested on other platforms....
--- End quote ---
Still, it would be much easier for him to insert text in between by using TStringList. There is no method that pushes next bytes forward by written amount.
chim:
Thank you Guys for pointing me in the right direction.
I use now the LoadfromFile Method.
everything works well.
chim:
Hello Pros,
could you please help me once again? :-[
My code work for me just fine for one file, my problem is to get this actions to every file in my Memo3.
To make this clear what my App does:
I got a HTML Template, and i would change seperate parts of the file with new ones, and save this as a new file.
1) Choose Template
2) Template get loaded into Memo1
3) Pressing the Button will search and list every HTML File from the dir you choose into Memo3
4) Load into Memo4 the current file listed at first in Memo3
5) Load HTML Code from prelisted locations of Memo4 and write it to Memo2
6) Write the HTML Code from Memo2 into Memo1 to the prelistet locations
7) Save File and repeat the Step 4) to Step 7) until every file from Memo3 was done
So thats my plan, unfortunately it does this actions just one time, and i can't figure out why :(
Could you please help me again?
here is the code:
Yes i know its a mess :-[
--- Code: ---procedure TForm1.Button2Click(Sender: TObject);
var
i: integer;
Ini: TIniFile;
Pfad: String;
Pfad2: Integer;
Save: String;
begin
If comboBox1.Text ='Vorlage wählen...' then
begin
showmessage('Bitte Vorlage wählen!');
end
else
If comboBox1.Text ='Normalglas' then
begin
if SelectDirectoryDialog1.Execute then
begin
GetFilesInDirectory(SelectDirectoryDialog1.FileName, '*.html', Memo3.Lines, True, True);
begin
for i:=0 to Memo3.Lines.Count-1 do
Ini:=TIniFile.Create(GetApplicationDirectory+'Vorlagen.ini');
try
Pfad := Ini.ReadString('Normalglas', 'Pfad', '');
Memo1.Lines.LoadFromFile(GetApplicationDirectory+Pfad);
finally
Ini.Free;
begin
Memo4.Lines.LoadFromFile(Memo3.Lines[i]);
Memo2.Lines.Add(String(Memo4.Lines[12]));
Memo2.Lines.Add(String(Memo4.Lines[14]));
Memo2.Lines.Add(String(Memo4.Lines[15]));
Memo2.Lines.Add(String(Memo4.Lines[38]));
Memo2.Lines.Add(String(Memo4.Lines[50]));
Memo2.Lines.Add(String(Memo4.Lines[55]));
with ProgressBar1 do
begin
Ini:=TIniFile.Create(GetApplicationDirectory+'Vorlagen.ini');
try
Pfad2 := Ini.ReadInteger('Normalglas', 'Platzhalter1', 10);
Memo1.Lines[Pfad2]:= Memo2.Lines[0];
ProgressBar1.Position := 15;
Pfad2 := Ini.ReadInteger('Normalglas', 'Platzhalter2', 12);
Memo1.Lines[Pfad2]:= Memo2.Lines[1];
ProgressBar1.Position := 30;
Pfad2 := Ini.ReadInteger('Normalglas', 'Platzhalter3', 13);
Memo1.Lines[Pfad2]:= Memo2.Lines[2];
ProgressBar1.Position := 45;
Pfad2 := Ini.ReadInteger('Normalglas', 'Platzhalter4', 36);
Memo1.Lines[Pfad2]:= Memo2.Lines[3];
ProgressBar1.Position := 60;
Pfad2 := Ini.ReadInteger('Normalglas', 'Platzhalter5', 48);
Memo1.Lines[Pfad2]:= Memo2.Lines[4];
ProgressBar1.Position := 75;
Pfad2 := Ini.ReadInteger('Normalglas', 'Platzhalter6', 53);
Memo1.Lines[Pfad2]:= Memo2.Lines[5];
ProgressBar1.Position := 90;
finally
Ini.Free;
Save:=(Memo3.Lines[0]+'glas.html');
Memo1.Lines.SaveToFile(Save);
ProgressBar1.Position := 100;
end;
end;
end;
end;
end;
end;
end;
end;
--- End code ---
BigChimp:
Could you please start a new thread for new questions? (Just copying over the contents of your previous post is fine ;) )
It cuts down on confusion, helps other when searching the forums for problems and solutions etc.
Danke!
chim:
All right Thank you
Navigation
[0] Message Index
[*] Previous page