Solved

Save component's status--A Simple question?

Posted on 2000-04-02
10
173 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
creating manifest for my dll that called from activex 6 114
delphi exception 7 64
Strange behavior when a form is closed 6 57
Wincontrol not (correctly) drawn 15 38
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 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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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