Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Save component's status--A Simple question?

Posted on 2000-04-02
10
Medium Priority
?
187 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 200 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

704 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