Solved

saving and loading problem

Posted on 1998-04-06
3
138 Views
Last Modified: 2012-05-04
how can u save a Tlabel and a timage at the same file using savetofile method and can load the same file with the timageand tlabel and its original properties like the font color, the font style etc. can anybody give a sample code for this problem.
0
Comment
Question by:SABOG7
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
extreme earned 50 total points
ID: 1361314
Youy need to use streams for this. You have to do someting like this:

var
  s : TFileStream;
begin
  s := TFileStream.Create ('thefile', fmCreate);
  try
    s.WriteComponent (Label1);
    s.WriteComponent (Image1);
  finally
    s.Free;
  end;
end;

for read the components simply do:

var
  s : TFileStream;
begin
  s := TFileStream.Create ('thefile', fmOpenRead);
  try
    s.ReadComponent (Label1);
    s.ReadComponent (Image1);
  finally
    s.Free;
  end;
end;

the code above will work if the Label1 and Image1 are created, if not the you should assignt the value of ReadComponent to it and pass a nil parameter to readcomponent, something like this:

Label1 := s.ReadComponent (nil);

that line created in component, as contrary to

s.ReadComponent (Label1)

that load the contents of the label stored in the stream in the label already create.

Is important to make you note that in order to make this work you have to register the clases TLabel and TImage first. This ciuld be dont in the OnCreate event handler of your main form, or in the initialization part of some unit.

The code to register the classes is:

RegisterClass (TLabel);
REgisterclass (TImage);

If you have some problem with the registerclass method could be because you have the Windows unit declared after than the Classes unit. In such case write:

Classes.RegisterClass (TLabel);
Classes.Registerclass (TImage);

That should work.

0
 

Author Comment

by:SABOG7
ID: 1361315
you got an extreme answear. its very simple and accurate. were did you learn how to do that master EXREME. UR THE BEST .....thank you very very much.. from now on u r my IDOL....

from asher of the philippines......
0
 
LVL 1

Expert Comment

by:extreme
ID: 1361316
Thanks for your praises, :). I'm from Argentina, and I learned most I know simply programming, as you can do. Anyway I readed some book to increase my skills in some matters non well documented.

Salutes from here!!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…

679 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