• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 802
  • Last Modified:

save object

How save an object in Delphi ?
0
hoff
Asked:
hoff
1 Solution
 
mirek071497Commented:
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
 
MatveyCommented:
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
 
viktornetCommented:
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
 
d003303Commented:
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now