Solved

save object

Posted on 1998-07-26
4
794 Views
Last Modified: 2013-11-23
How save an object in Delphi ?
0
Comment
Question by:hoff
[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
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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