Solved

saving and loading problem

Posted on 1998-04-06
3
134 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now