Solved

save object

Posted on 1998-07-26
4
790 Views
Last Modified: 2013-11-23
How save an object in Delphi ?
0
Comment
Question by:hoff
4 Comments
 
LVL 3

Expert Comment

by:mirek071497
ID: 1358695
There is no global proc for owner created objects however you can look at the TWriter and TReader.
Generally You must write code to save proprties which is needed for you.
Please tell us more, especially how you need to manipulate the saved objects and what objects you need to save.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1358696
You can look at the way Delphi forms are saved. These are basically text files. If you put an image on your form and open a picture in it, when you save the form you'll see how it stores the picture inside the .DFM file.
You can store properties in INI files and inside the rigistry. Use TRegistry or something more inhanced for that. I think it can't store sufisticated objects though. I'm not sure and someone please correct me if I'm wrong.
0
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1358697
There is actually a way to save components.....I'm not sure if it works for objects... Here is the way you read and write components to a file, no matter if it is .ini, or.dat...anyway.....here it is...
procedure Write_Comp;
var Stream_Name : TFileStream;
begin
  Stream_Name  :=  TFileStream.Create('NameOfFile.ini', fmCreate);
  try
    Stream_Name.WriteComponent(Button);
  finally
    Stream_Name.destroy;
  end;
end;

procedure Read_Comp;
var Stream_Name : TFileStream;
begin
  if FileExists('NameOfFile.ini') then
    begin
      Stream_Name := TFileStream.Create('NameOfFile.ini', fmOpenRead);
     try
       Button := Stream_Name.ReadComponent(Button) as TButton;
     finally
       Stream_Name.destroy;
     end;

That's all...I hope that's what you need...Talk to ya later!

Viktor Ivanov
  end;
end;


0
 
LVL 4

Expert Comment

by:d003303
ID: 1358698
Any descendant of the TPersistent object can use Delphis streaming services. Take a look at the online help of TPersistent. You will have to overwrite the DefineProperties to introduce special data to be read/written, published properties are handled automatically.
However, the easiest way is if your persistent object is contained in a component property. Then call ReadComponent/WriteComponent as viktornet proposed.

Slash/d003303
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

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

13 Experts available now in Live!

Get 1:1 Help Now