Solved

save object

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

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

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 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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

16 Experts available now in Live!

Get 1:1 Help Now