Solved

Treeview with LoadFromStream

Posted on 2003-10-24
3
1,056 Views
Last Modified: 2010-04-05
===============================
    a:=tstringlist.create;
    a.LoadFromFile(treename);
    for i:=0 to a.Count-1 do begin
        stemp:=a.Strings[i];
        if pos('====',stemp)=1 then begin
            for j:=i to a.count-1 do
                a.Delete(a.Count-1);
            goto oki;
        end;//if
    end;//for
    oki:
    st:=tstream.Create;
    a.SaveToStream(st);
    st.Position:=0;
    tree.LoadFromStream(st);
    a.Free;
    st.Free;
==============================
1. "treename" is a file saved as treeview1.savetofile(...)
2. after treename is saved, there is more text added in the tree file, at the end of the file
3. the code above tryed to load the info back in the tree, ignoring the lines written after "=========" line (those lines are deleted)
4. the ideea is :
   a. load the entire file into a tstring object
   b. delete the lines after "======" line
   c. copy the remanis into a stream
   d. load from stream into treeview

Something is wrong in my code. I get an "abstract...." error. help.
0
Comment
Question by:Catalin80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
Kalroth earned 50 total points
ID: 9613770
When you create the stream ("st" variable), use "tmemorystream" instead of "tstream", that's why you get an abstract error.

Instead of "goto oki;" just use "break", using goto gives me the shivers. :)
0
 
LVL 2

Expert Comment

by:Kalroth
ID: 9613788
This works fine for me.

(** CODE EXAMPLE **)

procedure TForm1.Button1Click(Sender: TObject);
var
  i, j: integer;
  stemp: string;
  a : tstringlist;
  st : tmemorystream;
begin
  a:=tstringlist.create;
  try
    a.LoadFromFile('treetest.txt');
    for i:=0 to a.Count-1 do
    begin
      stemp:=a.Strings[i];
      if pos('====',stemp)=1 then
      begin
        for j:=i to a.count-1 do
          a.Delete(a.Count-1);
        break;
      end;//if
    end;//for

    st:=tmemorystream.Create;
    try
      a.SaveToStream(st);
      st.Position:=0;
      tree.LoadFromStream(st);
    finally
      st.Free;
    end;
  finally
    a.Free;
  end;
end;

(** /CODE EXAMPLE **)
0
 

Author Comment

by:Catalin80
ID: 9614455
I AGREE YOU 100% :
1. using goto gives me too the shivers. I just was in a hurry.
2.
"When you create the stream ("st" variable), use "tmemorystream" instead of "tstream", that's why you get an abstract error."

I thought it was so. It's like tstrings <-> tstringlist. Just didn't knew what was the "other" object.

Thx. alot.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question