Solved

Save component's status--A Simple question?

Posted on 2000-04-02
10
183 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

623 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