Solved

save object

Posted on 1998-07-26
4
793 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

861 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