writing to specific line in either Stringlist or document file

Hi! I've got a problem and it's about writing to specific lines in either a TStringList or a document file (end result is always a .txt or .html file) ...

So basic problem : I've got text in 2 RichEdit's and i want the text to intertwine itself when i write it to my file ...example is :
(RE=RichEdit)
RE1-text
RE2-text
RE1-text-from-2nd-line
RE2-text-from-2nd-line
and so on
So my question now is how do i do that...is it possible in TStringList?
P.s. my text may be long up to 100 lines ...

Please advise....thank you!

Comments

  • Wellyou have two options, one you can either use code to distribute the line to a 3rd richtext box and then use the build in functions to save.

    Of you write code and save directly to a text file.

    Personally I prefer the first one, but thats me... As far as I know you are not limited to a number of lines by any of the two methods so you can go mad....

    Code for the first option:
    Place a 3rd richedit on the form and make in not visible...



    Procedure Tform1.SaveMyFile(Filename: String);
    Var
    J,K : Integer;
    Str1,Str2 : String;
    Begin
    If Richedit1.Lines.Count-1 = Richedit2.Lines.Count-1 then
    K := Richedit1.lines.count-1 else
    Begin
    If Richedit1.Lines.Count-1 > Richedit2.Lines.COunt-1 then
    K := Richedit1.lines.count-1 else
    K := Richedit2.lines.count-1;
    End;

    Richedit3.Lines.Clear;
    For J := 0 to K do
    Begin
    Str1 := '';
    Str2 := '';
    If J <= Richedit1.Lines.Count-1 then
    Str1 := Richedit1.Lines.Strings[J];
    If J <= Richedit1.LInes.Count-1 then
    Str2 := Richedit2.Lines.Strings[J];
    If Str1 <> '' then
    Richedit3.Lines.add(Str1);
    If Str2 <> '' then
    Richedit3.Lines.Add(Str1);
    End;
    Richedit3.Lines.savetofile(Filename);
    End;


    Code for option 2:

    Procedure TForm1.SaveMYFile
    Var
    F : TextFile;
    Str1,Str2 : String;
    J,K :Integer;
    Begin
    If Richedit1.Lines.Count-1 = Richedit2.Lines.Count-1 then
    K := Richedit1.lines.count-1 else
    Begin
    If Richedit1.Lines.Count-1 > Richedit2.Lines.COunt-1 then
    K := Richedit1.lines.count-1 else
    K := Richedit2.lines.count-1;
    End;
    Assignfile(F,'C:out.txt');
    rewrite(F);
    For J := 0 to K do
    Begin
    Str1 := '';
    Str2 := '';
    If J <= Richedit1.Lines.Count-1 then
    Str1 := Richedit1.Lines.Strings[J];
    If J <= Richedit1.LInes.Count-1 then
    Str2 := Richedit2.Lines.Strings[J];
    If Str1 <> '' then
    Write(F,Str1);
    If Str2 <> '' then
    Write(F,Str2);
    End;
    Closefile(F);
    End;

    hope this helped you out!!!

    Darkwing Duck aka DWduck signing off :)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion