Solved

Save component's status--A Simple question?

Posted on 2000-04-02
10
176 Views
Last Modified: 2010-04-04
hi friends:
    I want a common way to save all component's status (including captions, colors, posions ect.). I know I can write them into registry or ini file one by one, but I really do not want to do so. I want a easy way like:
for i:=0 to componentcount-1
begin
 with components[i] do
 begin
  for j := 0 to propertisecount - 1
   SavePropertise(Component[i],propertise[j]);
 end;
end;

I want the answer in 1 days, else I'll delete the question, thanx a lot.
I just want code not component, thanx again.
0
Comment
Question by:chengjian
  • 3
  • 2
  • 2
  • +2
10 Comments
 

Expert Comment

by:hoschmi
ID: 2677653
you cant write data in your compiled exe-file!
you must use a configuration or ini-file, in which all data is written e.g. onClose.use a configuration type like
 Tconfiguration = record
     text1 : string;
     text2 : string;
     ....
   end;

then make a variable
 config : Tconfiguration;

write everything in it onClose like
  config.text1:=edit1.text;
 ...

then save it in your config file like
savefile : file of Tconfiguration;
....
write(savefile,config)
....


0
 

Expert Comment

by:Carpathia
ID: 2677831
I dont think he wants to write the data to the exe, he just doesnt want to use ini or registry.

Try looking at the ReadComponent, and WriteComponent methods of TStream, or in this case, TFileStream.

Hope this helps
0
 

Expert Comment

by:Carpathia
ID: 2677833
One more thing..

For custom properties you might need to add the stored; directive after the property definition.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
LVL 17

Expert Comment

by:inthe
ID: 2677949
Marco Cantu's example of saving/restoring
ANY component, including an text EditBox (if that is
what you mean), using TStream.  The component be an
entire form full of components.  As long as the component's properties are published (i.e. the text in an
 edit box), it will work....and you have a persistent object  
 
from Marco Cantu, "Delphi Developer's Handbook",

Example assumes the component to be stored is an object named OutputForm....
 

var
  Str1 : TFileStream;
begin
   begin
    Str1 := TFileStream.Create (SomeFileName,
      fmOpenWrite or fmCreate);
try
      Str1.WriteComponentRes (         OutputForm.ClassName, OutputForm);//save the entire component
    finally
      Str1.Free;
    end;
  end;
end;
 
AND to read
 
var
  Str1: TFileStream;
  TempForm1: TOutputForm;
begin
    Str1 := TFileStream.Create (SomeFileName,
      fmOpenRead); //open a stream
    try
      TempForm1 := TOutputForm.Create (Application); //temp object       Str1.ReadComponentRes (TempForm1); OutputForm.Free; //destroy the existing component
      OutputForm := TempForm1;        
OutputForm.Show;      
    finally
      Str1.Free;
    end;
  end;
end;


See also, Earl F Glynn's links about
   Streams at
http://www.efg2.com/Lab/Library/Delphi/IO/StreamIO.htm
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2678621
RXLib www.rxlib.ru (or .com) has a great component to do that on a INI or Registry: TFormPlacement I think, check it
0
 
LVL 1

Author Comment

by:chengjian
ID: 2680371
Greatly thanx
First I do not want save propertises to exe.
Registry and Ini are acceptable.
but the problem is:
I do not want to save the propertises one by one. I want an easy and common way.
I have used either readcomponent and write component, it works, but, it saves the entire classes besides the propertises
if I have a button on form
when I read another button out, it should be two buttons:(

forgive my poor language
0
 
LVL 17

Expert Comment

by:inthe
ID: 2682075
maybe this example from torrys is a help:

http://torry.spang.org/samples/samples/saveprop.zip
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2683671
"
                    I do not want to save the propertises one by one. I want an easy and common way.
                    I have used either readcomponent and write component, it works, but, it saves the entire
                    classes besides the propertises
                    if I have a button on form
                    when I read another button out, it should be two buttons:( "

hmm, sorry if I'm a bit short in mind. .I don't understand at all what's the prob.. the component can save all the properties you want from any components you want..
0
 
LVL 1

Author Comment

by:chengjian
ID: 2689424
Ok, an example save component's property with both readcomponent and writecomponent would acceptable.
please send to:cjcjc@citiz.net
thanx a lot
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 2691342
procedure TForm1.Button1Click(Sender: TObject);
var
  Strm : TFileStream;
begin
  Strm := TFileStream.Create('Label1.dat', fmCreate);
  with Strm do
  try
    WriteComponent(Label1);
  finally
    Free;
  end;
end;
 
procedure TForm1.Button2Click(Sender: TObject);
var
  Strm : TFileStream;
begin
  if not FileExists('Label1.dat') then Exit;
  Strm := TFileStream.Create('Label1.dat', fmOpenRead);
  with Strm do
  try
    ReadComponent(Label1);
  finally
    Free;
  end;
end;
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

860 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