Solved

Treeview with LoadFromStream

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 71
Print Graphic and Text to Epson TM-T88v 12 168
tidtcpserver connection lost handle 2 69
Graphics32 under Delphi 10.1 Berlin 2 34
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…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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