Solved

Treeview with LoadFromStream

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now