Solved

Treeview with LoadFromStream

Posted on 2003-10-24
3
1,063 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

628 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